Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent TcpTransport initialization errors from stopping TcpServer #1175

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/impl/tcpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ shared_ptr<TcpTransport> TcpServer::accept() {
socket_t incomingSock = ::accept(mSock, (struct sockaddr *)&addr, &addrlen);

if (incomingSock != INVALID_SOCKET) {
return std::make_shared<TcpTransport>(incomingSock, nullptr); // no state callback

try {
return std::make_shared<TcpTransport>(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");
Expand Down
2 changes: 1 addition & 1 deletion src/impl/tcptransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<struct sockaddr *>(&addr), &addrlen) < 0)
throw std::runtime_error("getsockname failed");
throw std::runtime_error("getpeername failed");

unmap_inet6_v4mapped(reinterpret_cast<struct sockaddr *>(&addr), &addrlen);

Expand Down
Loading