mirror of
https://gitlab.com/obbart/universal_robots_ros_driver.git
synced 2026-04-10 10:00:48 +02:00
Fixed SO_REUSEADDR being set after bind rather than before
This commit is contained in:
@@ -15,11 +15,7 @@ private:
|
|||||||
TCPSocket client_;
|
TCPSocket client_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
|
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len);
|
||||||
{
|
|
||||||
return ::bind(socket_fd, address, address_len) == 0;
|
|
||||||
}
|
|
||||||
virtual void setOptions(int socket_fd);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
URServer(int port);
|
URServer(int port);
|
||||||
|
|||||||
@@ -14,14 +14,6 @@ URServer::~URServer()
|
|||||||
TCPSocket::close();
|
TCPSocket::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
sockaddr_in name;
|
sockaddr_in name;
|
||||||
@@ -39,6 +31,14 @@ std::string URServer::getIP()
|
|||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool URServer::open(int socket_fd, struct sockaddr *address, size_t address_len)
|
||||||
|
{
|
||||||
|
int flag = 1;
|
||||||
|
setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
|
||||||
|
return ::bind(socket_fd, address, address_len) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool URServer::bind()
|
bool URServer::bind()
|
||||||
{
|
{
|
||||||
std::string empty;
|
std::string empty;
|
||||||
@@ -65,7 +65,7 @@ bool URServer::accept()
|
|||||||
if (client_fd <= 0)
|
if (client_fd <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
setOptions(client_fd);
|
TCPSocket::setOptions(client_fd);
|
||||||
|
|
||||||
return client_.setSocketFD(client_fd);
|
return client_.setSocketFD(client_fd);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user