1
0
mirror of https://gitlab.com/obbart/universal_robots_ros_driver.git synced 2026-04-10 01:50:46 +02:00

Added set options function for sockets

This commit is contained in:
Simon Rasmussen
2017-05-19 01:22:42 +02:00
parent 8d845c6f38
commit 0c23d0bf3d
5 changed files with 19 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ protected:
{
return false;
}
virtual void setOptions(int socket_fd);
bool setup(std::string &host, int port);

View File

@@ -20,6 +20,8 @@ protected:
{
return ::bind(socket_fd, address, address_len) == 0;
}
virtual void setOptions(int socket_fd);
public:
URServer(int port);

View File

@@ -32,7 +32,7 @@ public:
}
void disconnect()
{
LOG_INFO("Disconnecting");
LOG_INFO("Disconnecting from %s:%d", host_.c_str(), port_);
TCPSocket::close();
}

View File

@@ -16,6 +16,12 @@ TCPSocket::~TCPSocket()
close();
}
void TCPSocket::setOptions(int socket_fd)
{
int flag = 1;
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));
}
bool TCPSocket::setup(std::string &host, int port)
{
if(state_ == SocketState::Connected)
@@ -63,6 +69,7 @@ bool TCPSocket::setup(std::string &host, int port)
}
else
{
setOptions(socket_fd_);
state_ = SocketState::Connected;
LOG_INFO("Connection established for %s:%d", host.c_str(), port);
}

View File

@@ -9,6 +9,14 @@ URServer::URServer(int port)
{
}
void URServer::setOptions(int socket_fd)
{
TCPSocket::setOptions(socket_fd);
int flag = 1;
setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
}
std::string URServer::getIP()
{
char buf[128];