@@ -90,7 +90,8 @@ void TcpTransport::stop() {
90
90
if (eventFd > 0 ) {
91
91
u_int64_t buf = 1 ;
92
92
LOG_DEBUG (" TCP Transport: write CTL fd" );
93
- write (eventFd, &buf, 8 );
93
+ if (write (eventFd, &buf, 8 ) <= 0 )
94
+ perror (" TCP Transport writing control socket failed: " );
94
95
}
95
96
96
97
std::vector<std::shared_ptr<TcpPeer>> tcpPeerV;
@@ -334,7 +335,7 @@ void TcpTransport::tcpTxThread(unsigned int id) {
334
335
perror (" epoll_ctl: " );
335
336
}
336
337
}
337
- do {
338
+ while (isServing) {
338
339
int cnt = ::epoll_wait (poll_fd, events, EPOLL_MAXEVENTS, -1 );
339
340
340
341
for (int i = 0 ; i < cnt; i++) {
@@ -383,7 +384,7 @@ void TcpTransport::tcpTxThread(unsigned int id) {
383
384
tcpPeers.remove (tcpPeer->Id );
384
385
}
385
386
}
386
- } while (isServing) ;
387
+ };
387
388
if (eventFd > 0 )
388
389
epoll_ctl (poll_fd, EPOLL_CTL_DEL, eventFd, NULL );
389
390
@@ -702,7 +703,7 @@ void TcpTransport::tcpRxThread(unsigned int id) {
702
703
}
703
704
}
704
705
705
- do {
706
+ while (isServing) {
706
707
int cnt = ::epoll_wait (poll_fd, events, EPOLL_MAXEVENTS, -1 );
707
708
708
709
for (int i = 0 ; i < cnt; i++) {
@@ -751,7 +752,7 @@ void TcpTransport::tcpRxThread(unsigned int id) {
751
752
}
752
753
}
753
754
}
754
- } while (isServing) ;
755
+ };
755
756
if (eventFd > 0 )
756
757
epoll_ctl (poll_fd, EPOLL_CTL_DEL, eventFd, NULL );
757
758
@@ -843,13 +844,16 @@ bool TcpTransport::addEndpointPassive(int sock) {
843
844
844
845
tep->sock = sock;
845
846
tcpPeer->addEndpoint (tep);
846
- activateEndpoint (tep, tcpPeer);
847
- LOG_DEBUG (" Server with " , tcpPeer->endpoints .size (),
848
- " connections to " , hostname, " ::" , in_peer->sin_port );
849
- return true ;
847
+ if (activateEndpoint (tep, tcpPeer) == true ) {
848
+ LOG_DEBUG (" Server with " , tcpPeer->endpoints .size (),
849
+ " connections to " , hostname, " ::" , in_peer->sin_port );
850
+ return true ;
851
+ }
852
+ tcpPeer->delEndpoint (tep);
853
+ LOG_ERROR (" Server failed adding connection to " , hostname, " ::" , in_peer->sin_port );
850
854
}
851
855
/*
852
- * Will kill this extra connection probably created during cross-connect
856
+ * Drop this extra connection probably created during cross-connect
853
857
* from both sides
854
858
*/
855
859
LOG_DEBUG (" Server with " , tcpPeer->endpoints .size () + 1 ,
@@ -915,10 +919,13 @@ std::shared_ptr<TcpPeer> TcpTransport::getPeer(sockaddr *peer) {
915
919
std::shared_ptr<TcpEndpoint> tep = std::make_shared<TcpEndpoint>();
916
920
tep->sock = sock;
917
921
tcpPeer->addEndpoint (tep);
918
- activateEndpoint (tep, tcpPeer);
919
-
922
+ if (activateEndpoint (tep, tcpPeer) == false ) {
923
+ tcpPeer->delEndpoint (tep);
924
+ ::close (sock);
925
+ LOG_ERROR (" Client failed adding connection to " , hostname, " ::" , inaddr->sin_port );
926
+ break ;
927
+ }
920
928
num_ep++;
921
-
922
929
LOG_DEBUG (" Client with " , num_ep, " connections to " , hostname, " ::" , inaddr->sin_port );
923
930
}
924
931
if (num_ep)
0 commit comments