diff --git a/src/impl/tcpserver.cpp b/src/impl/tcpserver.cpp index 25df61dcb..7e5777815 100644 --- a/src/impl/tcpserver.cpp +++ b/src/impl/tcpserver.cpp @@ -66,8 +66,12 @@ shared_ptr TcpServer::accept() { socket_t incomingSock = ::accept(mSock, (struct sockaddr *)&addr, &addrlen); if (incomingSock != INVALID_SOCKET) { - return std::make_shared(incomingSock, nullptr); // no state callback - + try { + return std::make_shared(incomingSock, nullptr); // no state callback + } catch(const std::exception &e) { + PLOG_WARNING << e.what(); + ::closesocket(incomingSock); + } } else if (sockerrno != SEAGAIN && sockerrno != SEWOULDBLOCK) { PLOG_ERROR << "TCP server failed, errno=" << sockerrno; throw std::runtime_error("TCP server failed"); diff --git a/src/impl/tcptransport.cpp b/src/impl/tcptransport.cpp index b3af2c209..a83fda958 100644 --- a/src/impl/tcptransport.cpp +++ b/src/impl/tcptransport.cpp @@ -69,7 +69,7 @@ TcpTransport::TcpTransport(socket_t sock, state_callback callback) struct sockaddr_storage addr; socklen_t addrlen = sizeof(addr); if (::getpeername(mSock, reinterpret_cast(&addr), &addrlen) < 0) - throw std::runtime_error("getsockname failed"); + throw std::runtime_error("getpeername failed"); unmap_inet6_v4mapped(reinterpret_cast(&addr), &addrlen);