Commit bba2ab70 authored by Felix Exner's avatar Felix Exner
Browse files

Close all closable sockets

Sockets do not necessarily have to be in state connected when they should be
closed. Before, only connected sockets got closed leading to a "socket leak"
if a socket was disconnected before a close request was processed.

With this fix all sockets with a valid file descriptor get closed when close()
is being called.
parent f2db8f3d
......@@ -102,9 +102,6 @@ bool URServer::accept()
void URServer::disconnectClient()
{
if (client_.getState() != comm::SocketState::Connected)
return;
client_.close();
}
......
......@@ -118,11 +118,12 @@ bool TCPSocket::setSocketFD(int socket_fd)
void TCPSocket::close()
{
if (state_ != SocketState::Connected)
return;
state_ = SocketState::Closed;
::close(socket_fd_);
socket_fd_ = -1;
if (socket_fd_ >= 0)
{
state_ = SocketState::Closed;
::close(socket_fd_);
socket_fd_ = -1;
}
}
std::string TCPSocket::getIP() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment