Unverified Commit e3554daf authored by Felix Exner's avatar Felix Exner Committed by GitHub
Browse files

Merge pull request #93 from UniversalRobots/fix_sockets_close

Close all closable sockets
parents f2db8f3d 46e7a72d
......@@ -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
......
......@@ -204,6 +204,11 @@ void UrDriver::startWatchdog()
LOG_INFO("Connection to robot dropped, waiting for new connection.");
handle_program_state_(false);
// We explicitly call the destructor here, as unique_ptr.reset() creates a new object before
// replacing the pointer and destroying the old object. This will result in a resource conflict
// when trying to bind the socket.
// TODO: It would probably make sense to keep the same instance alive for the complete runtime
// instead of killing it all the time.
reverse_interface_->~ReverseInterface();
reverse_interface_.reset(new comm::ReverseInterface(reverse_port_));
reverse_interface_active_ = true;
......
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