Skip to content

Commit

Permalink
Merge branch 'master' into feature/mars_for_github
Browse files Browse the repository at this point in the history
  • Loading branch information
jehoochen committed Jul 10, 2017
2 parents f27fcd3 + 92ef750 commit 1676c78
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 15 deletions.
115 changes: 113 additions & 2 deletions mars/app/app_logic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@
*/

#include "mars/app/app_logic.h"

#ifdef __APPLE__
#include <TargetConditionals.h>
#endif

#include "mars/comm/xlogger/xlogger.h"
#include "mars/comm/bootrun.h"
#include "mars/comm/thread/mutex.h"
#include "mars/comm/thread/lock.h"
#include "mars/comm/thread/thread.h"
#include "mars/comm/time_utils.h"
#include "mars/comm/dns/dns.h"
#include "mars/baseevent/baseprjevent.h"

namespace mars {
namespace app {
Expand All @@ -42,9 +54,101 @@ void SetCallback(Callback* const callback) {
}

#ifndef ANDROID

static mars::comm::ProxyInfo sg_proxyInfo;
static bool sg_gotProxy = false;
static Mutex sg_slproxymutex;
static Thread sg_slproxyThread;
static uint64_t sg_slporxytimetick = gettickcount();
static int sg_slproxycount = 0;

static void __ClearProxyInfo() {
ScopedLock lock(sg_slproxymutex);
sg_slporxytimetick = gettickcount();
sg_slproxycount = 0;
sg_gotProxy = false;
sg_proxyInfo.type = mars::comm::kProxyNone;
}

static void __GetProxyInfo(const std::string& _host, uint64_t _timetick) {
xinfo_function(TSF"timetick:%_, host:%_", _timetick, _host);

mars::comm::ProxyInfo proxy_info;
if (!sg_callback->GetProxyInfo(_host, proxy_info)) {
ScopedLock lock(sg_slproxymutex);
if (_timetick != sg_slporxytimetick) {
return;
}
++ sg_slproxycount;
return;
}

ScopedLock lock(sg_slproxymutex);
if (_timetick != sg_slporxytimetick) {
return;
}

++ sg_slproxycount;

sg_proxyInfo = proxy_info;

if (mars::comm::kProxyNone == sg_proxyInfo.type || !sg_proxyInfo.ip.empty() || sg_proxyInfo.host.empty()) {
sg_gotProxy = true;
return;
}

std::string host = sg_proxyInfo.host;
lock.unlock();

static DNS s_dns;
std::vector<std::string> ips;
s_dns.GetHostByName(host, ips);

if (ips.empty()) {
return;
}

lock.lock();
sg_proxyInfo.ip = ips.front();
sg_gotProxy = true;

}

static void __InitbindBaseprjevent() {
GetSignalOnNetworkChange().connect(&__ClearProxyInfo);
}


#if TARGET_OS_IPHONE
BOOT_RUN_STARTUP(__InitbindBaseprjevent);
#endif

mars::comm::ProxyInfo GetProxyInfo(const std::string& _host) {
xassert2(sg_callback != NULL);
return sg_callback->GetProxyInfo(_host);

#if !TARGET_OS_IPHONE
mars::comm::ProxyInfo proxy_info;
sg_callback->GetProxyInfo(_host, proxy_info);
return proxy_info;
#endif

if (sg_gotProxy) {
return sg_proxyInfo;
}

ScopedLock lock(sg_slproxymutex, false);
if (!lock.timedlock(500)) return mars::comm::ProxyInfo();

if (sg_slproxycount < 3 || 5 * 1000 > gettickspan(sg_slporxytimetick)) {
sg_slproxyThread.start(boost::bind(&__GetProxyInfo, _host, sg_slporxytimetick));
}

if (sg_gotProxy) {
return sg_proxyInfo;
}

return mars::comm::ProxyInfo();

}

std::string GetAppFilePath() {
Expand Down Expand Up @@ -76,7 +180,14 @@ void SetCallback(Callback* const callback) {

DeviceInfo GetDeviceInfo() {
xassert2(sg_callback != NULL);
return sg_callback->GetDeviceInfo();

static DeviceInfo device_info;
if (!device_info.devicename.empty() || !device_info.devicetype.empty()) {
return device_info;
}

device_info = sg_callback->GetDeviceInfo();
return device_info;
}


Expand Down
2 changes: 1 addition & 1 deletion mars/app/app_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace app {
public:
virtual ~Callback() {};

virtual mars::comm::ProxyInfo GetProxyInfo(const std::string& _host) { return mars::comm::ProxyInfo(); }
virtual bool GetProxyInfo(const std::string& _host, mars::comm::ProxyInfo& _proxy_info) { return false; }

virtual std::string GetAppFilePath() = 0;

Expand Down
4 changes: 2 additions & 2 deletions mars/app/win32proj/app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<ForcedIncludeFiles>mars/comm/projdef.h</ForcedIncludeFiles>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(ProjectDir)../../../;$(ProjectDir)../../comm/windows/</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../../comm/;$(ProjectDir)../../;$(ProjectDir)../../../;$(ProjectDir)../../comm/windows/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -79,7 +79,7 @@
<ForcedIncludeFiles>mars/comm/projdef.h</ForcedIncludeFiles>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(ProjectDir)../../../;$(ProjectDir)../../comm/windows/</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../../comm/;$(ProjectDir)../../;$(ProjectDir)../../../;$(ProjectDir)../../comm/windows/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
2 changes: 0 additions & 2 deletions mars/comm/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,7 @@ Parser::TRecvStatus Parser::Recv(const void* _buffer, size_t _length) {
return recvstatus_;
}

recvstatus_ = kHeaderFields;
headerbuf_.Write(recvbuf_.Ptr(), firstlinelength);
recvbuf_.Move(- firstlinelength);
// HTTP/1.1 4.7 Unauthorized\r\n\r\n
char* pos_2crlf = string_strnstr(pBuf, "\r\n\r\n", (int)recvbuf_.Length());
if (NULL != pos_2crlf && pos_2crlf == pos) {
Expand Down
4 changes: 4 additions & 0 deletions mars/comm/messagequeue/message_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@ static void __ReleaseMessageQueueInfo() {
const static int kMQCallANRId = 110;
const static long kWaitANRTimeout = 5 * 1000;
static void __ANRAssert(bool _iOS_style, const mars::comm::check_content& _content, MessageQueue_t _mq_id) {
if(MessageQueue2TID(_mq_id) == 0) {
xwarn2(TSF"messagequeue already destroy:%_", _mq_id);
return;
}

__ASSERT2(_content.file.c_str(), _content.line, _content.func.c_str(), "anr dead lock", "timeout:%d, tid:%" PRIu64 ", runing time:%" PRIu64 ", real time:%" PRIu64 ", used_cpu_time:%" PRIu64 ", iOS_style:%d",
_content.timeout, _content.tid, clock_app_monotonic() - _content.start_time, gettickcount() - _content.start_tickcount, _content.used_cpu_time, _iOS_style);
Expand Down
1 change: 1 addition & 0 deletions mars/comm/windows/thread/lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "assert/__assert.h"
#include "thread/mutex.h"
#include "thread/spinlock.h"
#include "unistd.h"

template <typename MutexType>
class BaseScopedLock {
Expand Down
4 changes: 2 additions & 2 deletions mars/stn/src/longlink_connect_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ bool LongLinkConnectMonitor::MakeSureConnected() {
}

bool LongLinkConnectMonitor::NetworkChange() {
xdebug_function();
#ifdef __APPLE__
xinfo_function();
#if 0//def __APPLE__
__StopTimer();

do {
Expand Down
2 changes: 1 addition & 1 deletion mars/stn/src/longlink_task_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ unsigned int LongLinkTaskManager::GetTasksContinuousFailCount() {
}

void LongLinkTaskManager::RedoTasks() {
xdebug_function();
xinfo_function();

std::list<TaskProfile>::iterator first = lst_cmd_.begin();
std::list<TaskProfile>::iterator last = lst_cmd_.end();
Expand Down
3 changes: 1 addition & 2 deletions mars/stn/src/net_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void NetCore::ClearTasks() {

void NetCore::OnNetworkChange() {

ASYNC_BLOCK_START
SYNC2ASYNC_FUNC(boost::bind(&NetCore::OnNetworkChange, this)); //if already messagequeue, no need to async

xinfo_function();

Expand Down Expand Up @@ -441,7 +441,6 @@ void NetCore::OnNetworkChange() {
shortlink_try_flag_ = false;
shortlink_error_count_ = 0;

ASYNC_BLOCK_END
}

void NetCore::KeepSignal() {
Expand Down
2 changes: 1 addition & 1 deletion mars/stn/src/net_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ void NetSource::ReportShortIP(bool _is_success, const std::string& _ip, const st
}

void NetSource::ClearCache() {
xverbose_function();
xinfo_function();
ipportstrategy_.InitHistory2BannedList(true);
}

Expand Down
2 changes: 1 addition & 1 deletion mars/stn/src/netsource_timercheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ NetSourceTimerCheck::~NetSourceTimerCheck() {

void NetSourceTimerCheck::CancelConnect() {
RETURN_NETCORE_SYNC2ASYNC_FUNC(boost::bind(&NetSourceTimerCheck::CancelConnect, this));
xdebug_function();
xinfo_function();

if (!thread_.isruning()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion mars/stn/src/shortlink_task_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void ShortLinkTaskManager::__OnRecv(ShortLinkInterface* _worker, unsigned int _c
}

void ShortLinkTaskManager::RedoTasks() {
xdebug_function();
xinfo_function();

std::list<TaskProfile>::iterator first = lst_cmd_.begin();
std::list<TaskProfile>::iterator last = lst_cmd_.end();
Expand Down
1 change: 1 addition & 0 deletions mars/stn/src/zombie_task_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void ZombieTaskManager::ClearTasks()

void ZombieTaskManager::RedoTasks()
{
xinfo_function();
__StartTask();
}

Expand Down

0 comments on commit 1676c78

Please sign in to comment.