Skip to content

Commit

Permalink
Properly disconnect when reading from socket fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauch committed Mar 16, 2021
1 parent 4126409 commit 341b34f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/comm/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,23 @@ void TCPServer::readData(const int fd)
{
bzero(&input_buffer_, INPUT_BUFFER_SIZE); // clear input buffer
int nbytesrecv = recv(fd, input_buffer_, INPUT_BUFFER_SIZE, 0);
if (nbytesrecv <= 0)
if (nbytesrecv > 0)
{
if (0 == nbytesrecv)
message_callback_(fd, input_buffer_);
}
else
{
if (0 < nbytesrecv)
{
handleDisconnect(fd);
return;
// Do we want to keep this error output?
URCL_LOG_ERROR("recv() on FD %d failed.", fd);
}
else
{
URCL_LOG_ERROR("recv() failed");
// normal disconnect
}
close(fd);
FD_CLR(fd, &masterfds_);
return;
handleDisconnect(fd);
}
message_callback_(fd, input_buffer_);
}

void TCPServer::worker()
Expand Down

0 comments on commit 341b34f

Please sign in to comment.