Skip to content

Commit 4978ea7

Browse files
Prevent TcpTransport initialization errors from stopping TcpServer
1 parent 8116593 commit 4978ea7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/impl/tcpserver.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ shared_ptr<TcpTransport> TcpServer::accept() {
6666
socket_t incomingSock = ::accept(mSock, (struct sockaddr *)&addr, &addrlen);
6767

6868
if (incomingSock != INVALID_SOCKET) {
69-
return std::make_shared<TcpTransport>(incomingSock, nullptr); // no state callback
70-
69+
try {
70+
return std::make_shared<TcpTransport>(incomingSock, nullptr); // no state callback
71+
} catch(const std::exception &e) {
72+
PLOG_WARNING << e.what();
73+
::closesocket(incomingSock);
74+
}
7175
} else if (sockerrno != SEAGAIN && sockerrno != SEWOULDBLOCK) {
7276
PLOG_ERROR << "TCP server failed, errno=" << sockerrno;
7377
throw std::runtime_error("TCP server failed");

0 commit comments

Comments
 (0)