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:
@@ -25,6 +25,7 @@ protected:
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
virtual void setOptions(int socket_fd);
|
||||||
|
|
||||||
|
|
||||||
bool setup(std::string &host, int port);
|
bool setup(std::string &host, int port);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ protected:
|
|||||||
{
|
{
|
||||||
return ::bind(socket_fd, address, address_len) == 0;
|
return ::bind(socket_fd, address, address_len) == 0;
|
||||||
}
|
}
|
||||||
|
virtual void setOptions(int socket_fd);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
URServer(int port);
|
URServer(int port);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
}
|
}
|
||||||
void disconnect()
|
void disconnect()
|
||||||
{
|
{
|
||||||
LOG_INFO("Disconnecting");
|
LOG_INFO("Disconnecting from %s:%d", host_.c_str(), port_);
|
||||||
TCPSocket::close();
|
TCPSocket::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ TCPSocket::~TCPSocket()
|
|||||||
close();
|
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)
|
bool TCPSocket::setup(std::string &host, int port)
|
||||||
{
|
{
|
||||||
if(state_ == SocketState::Connected)
|
if(state_ == SocketState::Connected)
|
||||||
@@ -63,6 +69,7 @@ bool TCPSocket::setup(std::string &host, int port)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
setOptions(socket_fd_);
|
||||||
state_ = SocketState::Connected;
|
state_ = SocketState::Connected;
|
||||||
LOG_INFO("Connection established for %s:%d", host.c_str(), port);
|
LOG_INFO("Connection established for %s:%d", host.c_str(), port);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
std::string URServer::getIP()
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|||||||
Reference in New Issue
Block a user