Skip to content

Commit 3432c78

Browse files
committed
hide signalkeeper from netcore
1 parent e8fcaa9 commit 3432c78

File tree

7 files changed

+46
-13
lines changed

7 files changed

+46
-13
lines changed

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/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/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/stn/src/net_core.cc

Lines changed: 12 additions & 2 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

@@ -443,6 +445,14 @@ void NetCore::OnNetworkChange() {
443445
ASYNC_BLOCK_END
444446
}
445447

448+
void NetCore::KeepSignal() {
449+
signalling_keeper_->Keep();
450+
}
451+
452+
void NetCore::StopSignal() {
453+
signalling_keeper_->Stop();
454+
}
455+
446456
#ifdef USE_LONG_LINK
447457
#ifdef __APPLE__
448458
void NetCore::__ResetLongLink() {

mars/stn/src/net_core.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ class NetCore {
8383
bool LongLinkIsConnected();
8484
void OnNetworkChange();
8585

86+
void KeepSignal();
87+
void StopSignal();
88+
8689
#ifdef USE_LONG_LINK
87-
SignallingKeeper& GetSignallingKeeper() {return *signalling_keeper_;}
8890
LongLinkTaskManager& GetLongLinkTaskManager() {return *longlink_task_manager_;}
89-
NetSourceTimerCheck& GetNetSourceTimerCheck() {return *netsource_timercheck_;}
90-
ShortLinkTaskManager& GetShortLinkTaskManager() {return *shortlink_task_manager_;}
9191
#endif
9292

9393
private:

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)