Skip to content

Commit bb793a0

Browse files
committed
Merge remote-tracking branch 'origin/master' into upstream_master
2 parents 36a8850 + 3432c78 commit bb793a0

File tree

18 files changed

+80
-33
lines changed

18 files changed

+80
-33
lines changed

mars/comm/network/getdnssvraddrs.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ void getdnssvraddrs(std::vector<socket_address>& _dnssvraddrs) {
5858
res_ndestroy(&stat);
5959
}
6060

61-
#elif defined WP8
62-
void getdnssvraddrs(std::vector<socket_address>& _dnssvraddrs) {
63-
}
6461
#elif defined _WIN32
6562
#include <stdio.h>
6663
#include <windows.h>
@@ -86,5 +83,6 @@ void getdnssvraddrs(std::vector<socket_address>& _dnssvraddrs) {
8683
return;
8784
}
8885
#else
89-
#error "no imp"
86+
void getdnssvraddrs(std::vector<socket_address>& _dnssvraddrs) {
87+
}
9088
#endif

mars/comm/network/getifaddrs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <string>
2424
#include <vector>
25+
#include <string.h>
2526

2627
struct ifaddrinfo_ipv4_t
2728
{

mars/comm/socket/socket_address.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "unix_socket.h"
2525

26-
#include <string>
26+
#include <string.h>
2727

2828
class socket_address {
2929

mars/comm/socket/tcp_fsm_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
template<class InputIterator>
2727
bool TcpFSMHandler(InputIterator _first, InputIterator _last, SocketSelectBreaker& _breaker, bool _select_anyway)
2828
{
29+
xverbose_function();
2930
xgroup2_define(group);
3031

3132
SocketSelect sel(_breaker, true);

mars/comm/socket/tcpclient.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ void TcpClient::__Run() {
180180

181181
int ret = ::connect(socket_, (sockaddr*)&_addr, sizeof(_addr));
182182

183+
std::string local_ip = socket_address::getsockname(socket_).ip();
184+
unsigned int local_port = socket_address::getsockname(socket_).port();
185+
186+
xinfo2(TSF"sock:%_, local_ip:%_, local_port:%_, svr_ip:%_, svr_port:%_", socket_, local_ip, local_port, ip_, port_);
187+
183188
if (0 > ret && !IS_NOBLOCK_CONNECT_ERRNO(socket_errno)) {
184189
xerror2("connect errno=%d", socket_errno);
185190
status_ = kTcpConnectingErr;

mars/comm/socket/tcpserver_fsm.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "comm/socket/tcpserver_fsm.h"
2727

2828
TcpServerFSM::TcpServerFSM(SOCKET _socket)
29-
: status_(kAccept), sock_(_socket) {
29+
: status_(kAccept), sock_(_socket), is_write_fd_set_(false) {
3030
xassert2(INVALID_SOCKET != sock_);
3131
socklen_t addr_len = sizeof(addr_);
3232
xerror2_if(0 > getpeername(sock_, (sockaddr*)&addr_, &addr_len), TSF"getpeername:%_, %_", socket_errno, socket_strerror(socket_errno));
@@ -36,7 +36,7 @@ TcpServerFSM::TcpServerFSM(SOCKET _socket)
3636
}
3737

3838
TcpServerFSM::TcpServerFSM(SOCKET _socket, const sockaddr_in& _addr)
39-
: status_(kAccept), sock_(_socket), addr_(_addr) {
39+
: status_(kAccept), sock_(_socket), addr_(_addr) , is_write_fd_set_(false){
4040
memset(ip_, 0, sizeof(ip_));
4141
inet_ntop(addr_.sin_family, &(addr_.sin_addr), ip_, sizeof(ip_));
4242
}
@@ -120,7 +120,12 @@ TcpServerFSM::TSocketStatus TcpServerFSM::PreReadWriteSelect(SocketSelect& _sel,
120120
_sel.Read_FD_SET(sock_);
121121
_sel.Exception_FD_SET(sock_);
122122

123-
if (0 < send_buf_.Length())_sel.Write_FD_SET(sock_);
123+
if (0 < send_buf_.Length()) {
124+
WriteFDSet(true);
125+
_sel.Write_FD_SET(sock_);
126+
} else {
127+
WriteFDSet(false);
128+
}
124129

125130
return status_;
126131
}

mars/comm/socket/tcpserver_fsm.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#include "comm/autobuffer.h"
2525
#include "comm/socket/unix_socket.h"
26+
#include "comm/xlogger/xlogger.h"
27+
#include "comm/thread/mutex.h"
28+
#include "comm/thread/lock.h"
2629

2730
class XLogger;
2831
class SocketSelect;
@@ -51,6 +54,17 @@ class TcpServerFSM {
5154
size_t SendBufLen() {return send_buf_.Length();}
5255
void Close(bool _notify = true);
5356

57+
bool WriteFDSet()
58+
{
59+
ScopedLock lock (write_fd_set_mutex_);
60+
return is_write_fd_set_;
61+
}
62+
void WriteFDSet(bool _is_set) {
63+
xverbose_function(TSF"_is_set:%_, is_write_fd_set_:%_", _is_set, is_write_fd_set_);
64+
ScopedLock lock (write_fd_set_mutex_);
65+
is_write_fd_set_ = _is_set;
66+
}
67+
5468
virtual TSocketStatus PreSelect(SocketSelect& _sel, XLogger& _log);
5569
virtual TSocketStatus AfterSelect(SocketSelect& _sel, XLogger& _log);
5670
virtual int Timeout() const;
@@ -80,6 +94,9 @@ class TcpServerFSM {
8094

8195
AutoBuffer send_buf_;
8296
AutoBuffer recv_buf_;
97+
98+
bool is_write_fd_set_;
99+
Mutex write_fd_set_mutex_;
83100
};
84101

85102
#endif /* TcpServerFSM_H_ */

mars/comm/unix/thread/thread.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ class Thread {
373373
if (0 < strnlen((const char*)runableref->thread_name, sizeof(runableref->thread_name))) {
374374
#ifdef __APPLE__
375375
pthread_setname_np((const char*)runableref->thread_name);
376-
#else
376+
#elif defined(ANDROID)
377377
pthread_setname_np(runableref->tid, (const char*)runableref->thread_name);
378+
#else
379+
378380
#endif
379381
}
380382

mars/libraries/mars_android_sdk/jni/log_crypt.cc.rewriteme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string.h>
2525
#include <sys/time.h>
2626
#include <time.h>
27+
#include <stdio.h>
2728

2829
static const char kMagicSyncStart = '\x03';
2930
static const char kMagicAsyncStart ='\x05';

mars/libraries/mars_android_sdk/jni/longlink_packer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define STN_SRC_LONGLINK_PACKER_H_
2323

2424
#include <stdlib.h>
25+
#include <stdint.h>
2526

2627
#define LONGLINK_UNPACK_CONTINUE (-2)
2728
#define LONGLINK_UNPACK_FALSE (-1)

mars/libraries/mars_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
WIN_COPY_EXT_FILES = {"stn/proto/longlink_packer.h": "longlink_packer.h",
2525
"stn/proto/stnproto_logic.h": "stnproto_logic.h",
2626
"stn/proto/longlink_packer.cc__": "longlink_packer.cc.rewriteme",
27-
"comm/windows/projdef.h": "mars-open/comm/projdef.h",
28-
"comm/windows/sys/cdefs.h": "mars-open/comm/sys/cdefs.h",
29-
"comm/windows/sys/time.h": "mars-open/comm/sys/time.h"
27+
"comm/windows/projdef.h": "mars/comm/projdef.h",
28+
"comm/windows/sys/cdefs.h": "mars/comm/sys/cdefs.h",
29+
"comm/windows/sys/time.h": "mars/comm/sys/time.h"
3030
}
3131

3232
html_css = '''

mars/log/crypt/log_crypt.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string.h>
2525
#include <sys/time.h>
2626
#include <time.h>
27+
#include <stdio.h>
2728

2829
static const char kMagicSyncStart = '\x03';
2930
static const char kMagicAsyncStart ='\x05';

mars/stn/proto/longlink_packer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define STN_SRC_LONGLINK_PACKER_H_
2323

2424
#include <stdlib.h>
25+
#include <stdint.h>
2526

2627
#define LONGLINK_UNPACK_CONTINUE (-2)
2728
#define LONGLINK_UNPACK_FALSE (-1)

mars/stn/src/longlink.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,7 @@ void LongLink::__RunReadWrite(SOCKET _sock, ErrCmdType& _errtype, int& _errcode,
724724
if (nwrite_size <= (maxnwrite + it->writelen)) {
725725
xinfo2(TSF"taskid:%_, cmdid:%_, taskid:%_ ; ", it->taskid, it->cmdid, it->taskid) >> close_log;
726726
break;
727-
}
728-
else {
727+
} else {
729728
maxnwrite += it->writelen;
730729
xinfo2(TSF"taskid:%_, cmdid:%_, task_info:%_ ; ", it->taskid, it->cmdid, it->task_info) >> close_log;
731730
}
@@ -753,8 +752,7 @@ void LongLink::__RunReadWrite(SOCKET _sock, ErrCmdType& _errtype, int& _errcode,
753752
xinfo2(TSF"taskid:%_, cmdid:%_, task_info:%_; ", taskid, cmdid, sent_taskids[taskid]) >> close_log;
754753
if (LONGLINK_UNPACK_CONTINUE == unpackret || LONGLINK_UNPACK_FALSE == unpackret) {
755754
break;
756-
}
757-
else {
755+
} else {
758756
sent_taskids.erase(taskid);
759757
bufrecv.Move(-(int)(packlen));
760758
}
@@ -766,7 +764,7 @@ void LongLink::__RunReadWrite(SOCKET _sock, ErrCmdType& _errtype, int& _errcode,
766764
struct tcp_info _info;
767765
if (getsocktcpinfo(_sock, &_info) == 0) {
768766
char tcp_info_str[1024] = {0};
769-
xinfo2(TSF"task socket close getsocktcpinfo:%_", tcpinfo2str(&_info, tcp_info_str, sizeof(tcp_info_str))) >> close_log;
767+
xinfo2(TSF"task socket close getsocktcpinfo:%_", tcpinfo2str(&_info, tcp_info_str, sizeof(tcp_info_str))) >> close_log;
770768
}
771769
#endif
772770
}

mars/stn/src/net_core.cc

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
#include "boost/bind.hpp"
2626
#include "boost/ref.hpp"
2727

28+
#include "openssl/export_include/openssl_multi_thread_support.h"
29+
2830
#include "mars/app/app.h"
2931
#include "mars/baseevent/active_logic.h"
3032
#include "mars/comm/messagequeue/message_queue.h"
33+
#include "mars/comm/network/netinfo_util.h"
3134
#include "mars/comm/socket/local_ipstack.h"
3235
#include "mars/comm/xlogger/xlogger.h"
3336
#include "mars/comm/singleton.h"
@@ -51,8 +54,7 @@
5154

5255
#include "signalling_keeper.h"
5356
#include "zombie_task_manager.h"
54-
#include "openssl/export_include/openssl_multi_thread_support.h"
55-
#include "comm/network/netinfo_util.h"
57+
5658
using namespace mars::stn;
5759
using namespace mars::app;
5860

@@ -100,13 +102,6 @@ inline static bool __ValidAndInitDefault(Task& _task, XLogger& _group) {
100102

101103
static const int kShortlinkErrTime = 3;
102104

103-
enum {
104-
kCallFromLong,
105-
kCallFromShort,
106-
kCallFromZombie,
107-
};
108-
109-
110105

111106
NetCore::NetCore()
112107
: messagequeue_creater_(true, XLOGGER_TAG)
@@ -220,8 +215,7 @@ NetCore::~NetCore() {
220215
#ifdef USE_LONG_LINK
221216
GetSignalOnNetworkDataChange().disconnect(boost::bind(&SignallingKeeper::OnNetWorkDataChanged, signalling_keeper_, _1, _2, _3));
222217

223-
longlink_task_manager_->LongLinkChannel().SignalConnection.disconnect(boost::bind(&TimingSync::OnLongLinkStatuChanged, timing_sync_, _1));
224-
longlink_task_manager_->LongLinkChannel().SignalConnection.disconnect(boost::bind(&NetCore::__OnLongLinkConnStatusChange, this, _1));
218+
longlink_task_manager_->LongLinkChannel().SignalConnection.disconnect_all_slots();
225219
longlink_task_manager_->LongLinkChannel().broadcast_linkstatus_signal_.disconnect_all_slots();
226220

227221
push_preprocess_signal_.disconnect_all_slots();
@@ -451,6 +445,14 @@ void NetCore::OnNetworkChange() {
451445
ASYNC_BLOCK_END
452446
}
453447

448+
void NetCore::KeepSignal() {
449+
signalling_keeper_->Keep();
450+
}
451+
452+
void NetCore::StopSignal() {
453+
signalling_keeper_->Stop();
454+
}
455+
454456
#ifdef USE_LONG_LINK
455457
#ifdef __APPLE__
456458
void NetCore::__ResetLongLink() {
@@ -497,6 +499,12 @@ bool NetCore::LongLinkIsConnected() {
497499
}
498500

499501
int NetCore::__CallBack(int _from, ErrCmdType _err_type, int _err_code, int _fail_handle, const Task& _task, unsigned int _taskcosttime) {
502+
503+
if (task_callback_hook_ && 0 == task_callback_hook_(_from, _err_type, _err_code, _fail_handle, _task)) {
504+
xwarn2(TSF"task_callback_hook let task return. taskid:%_, cgi%_.", _task.taskid, _task.cgi);
505+
return 0;
506+
}
507+
500508
if (kEctOK == _err_type || kTaskFailHandleTaskEnd == _fail_handle)
501509
return OnTaskEnd(_task.taskid, _task.user_context, _err_type, _err_code);
502510

mars/stn/src/net_core.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,19 @@ class NetCheckLogic;
5757
class DynamicTimeout;
5858
class AntiAvalanche;
5959

60+
enum {
61+
kCallFromLong,
62+
kCallFromShort,
63+
kCallFromZombie,
64+
};
65+
6066
class NetCore {
6167
public:
6268
SINGLETON_INTRUSIVE(NetCore, new NetCore, NetCore::__Release);
6369

6470
public:
6571
boost::function<void (Task& _task)> task_process_hook_;
72+
boost::function<int (int _from, ErrCmdType _err_type, int _err_code, int _fail_handle, const Task& _task)> task_callback_hook_;
6673
boost::signals2::signal<void (uint32_t _cmdid, const AutoBuffer& _buffer)> push_preprocess_signal_;
6774

6875
public:
@@ -76,11 +83,11 @@ class NetCore {
7683
bool LongLinkIsConnected();
7784
void OnNetworkChange();
7885

86+
void KeepSignal();
87+
void StopSignal();
88+
7989
#ifdef USE_LONG_LINK
80-
SignallingKeeper& GetSignallingKeeper() {return *signalling_keeper_;}
8190
LongLinkTaskManager& GetLongLinkTaskManager() {return *longlink_task_manager_;}
82-
NetSourceTimerCheck& GetNetSourceTimerCheck() {return *netsource_timercheck_;}
83-
ShortLinkTaskManager& GetShortLinkTaskManager() {return *shortlink_task_manager_;}
8491
#endif
8592

8693
private:

mars/stn/stn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct Task {
4444

4545
static const int kChannelNormalStrategy = 0;
4646
static const int kChannelFastStrategy = 1;
47+
static const int kChannelDisasterRecoveryStategy = 2;
4748

4849
static const int kTaskPriorityHighest = 0;
4950
static const int kTaskPriority0 = 0;

mars/stn/stn_logic.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ void SetSignallingStrategy(long _period, long _keepTime) {
231231

232232
void KeepSignalling() {
233233
#ifdef USE_LONG_LINK
234-
STN_WEAK_CALL(GetSignallingKeeper().Keep());
234+
STN_WEAK_CALL(KeepSignal());
235235
#endif
236236
}
237237

238238
void StopSignalling() {
239239
#ifdef USE_LONG_LINK
240-
STN_WEAK_CALL(GetSignallingKeeper().Stop());
240+
STN_WEAK_CALL(StopSignal());
241241
#endif
242242
}
243243

0 commit comments

Comments
 (0)