20 # include <ace/INET_Addr.h>
21 # include <ace/os_include/netinet/os_tcp.h>
27 # include <netinet/tcp.h>
37 if (address.getPort() == -1) {
40 std::string host = address.getHost();
41 yarp::os::impl::TcpConnector connector;
43 if (address.getHost() ==
"localhost") {
47 ACE_INET_Addr addr(address.getPort(), host.c_str());
50 if (address.hasTimeout()) {
51 openTimeout.set(address.getTimeout());
52 timeout = &openTimeout;
54 int result = connector.connect(stream, addr, timeout, ACE_Addr::sap_any, 1);
58 if (address.hasTimeout()) {
61 timeout.tv_sec =
static_cast<int>(address.getTimeout());
62 timeout.tv_usec = (address.getTimeout() - timeout.tv_sec) * 1000000;
63 result = connector.connect(stream, address, &timeout);
65 result = connector.connect(stream, address,
nullptr);
74 "TCP connection to tcp:/%s failed to open",
75 address.toURI(
false).c_str());
83 int result = acceptor.accept(stream);
92 void SocketTwoWayStream::updateAddresses()
95 stream.set_option(IPPROTO_TCP, TCP_NODELAY, &one,
sizeof(
int));
99 stream.get_local_addr(local);
100 stream.get_remote_addr(remote);
102 char localHostAddress[256];
103 char remoteHostAddress[256];
104 local.get_host_addr(localHostAddress, 256);
105 remote.get_host_addr(remoteHostAddress, 256);
106 localAddress =
Contact(localHostAddress, local.get_port_number());
107 remoteAddress =
Contact(remoteHostAddress, remote.get_port_number());
109 struct sockaddr local;
110 struct sockaddr remote;
111 memset(&local, 0,
sizeof(local));
112 memset(&remote, 0,
sizeof(remote));
113 stream.get_local_addr(local);
114 stream.get_remote_addr(remote);
115 if (local.sa_family == AF_INET || local.sa_family == AF_INET6) {
116 char* localHostAddress =
new char[local.sa_family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN];
117 char* remoteHostAddress =
new char[remote.sa_family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN];
118 const char*
ret =
nullptr;
119 ret = inet_ntop(local.sa_family,
120 (local.sa_family == AF_INET ?
reinterpret_cast<void*
>(&
reinterpret_cast<struct sockaddr_in*
>(&local)->sin_addr) :
reinterpret_cast<void*
>(&
reinterpret_cast<struct sockaddr_in6*
>(&local)->sin6_addr)),
122 (local.sa_family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN));
124 localAddress =
Contact(localHostAddress, ntohs(
reinterpret_cast<struct sockaddr_in*
>(&local)->sin_port));
128 ret = inet_ntop(remote.sa_family,
129 (remote.sa_family == AF_INET ?
reinterpret_cast<void*
>(&
reinterpret_cast<struct sockaddr_in*
>(&remote)->sin_addr) :
reinterpret_cast<void*
>(&
reinterpret_cast<struct sockaddr_in6*
>(&remote)->sin6_addr)),
131 (remote.sa_family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN));
133 remoteAddress =
Contact(remoteHostAddress, ntohs(
reinterpret_cast<struct sockaddr_in*
>(&remote)->sin_port));
137 delete[] localHostAddress;
138 delete[] remoteHostAddress;
151 return (stream.set_option(IPPROTO_IP, IP_TOS, &tos,
static_cast<int>(
sizeof(tos))) == 0);
158 stream.get_option(IPPROTO_IP, IP_TOS, &tos, &optlen);