10 #if !defined ZMQ_HAVE_WINDOWS
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <netinet/tcp.h>
17 #ifdef ZMQ_HAVE_VXWORKS
22 #if defined ZMQ_HAVE_OPENVMS
27 #include <TargetConditionals.h>
37 setsockopt (
s_, IPPROTO_TCP, TCP_NODELAY,
38 reinterpret_cast<char *
> (&nodelay),
sizeof (
int));
43 #ifdef ZMQ_HAVE_OPENVMS
46 rc = setsockopt (
s_, IPPROTO_TCP, TCP_NODELACK, (
char *) &nodelack,
56 setsockopt (sockfd_, SOL_SOCKET, SO_SNDBUF,
57 reinterpret_cast<char *
> (&bufsize_),
sizeof bufsize_);
65 setsockopt (sockfd_, SOL_SOCKET, SO_RCVBUF,
66 reinterpret_cast<char *
> (&bufsize_),
sizeof bufsize_);
88 #ifdef ZMQ_HAVE_WINDOWS
89 if (keepalive_ != -1) {
90 tcp_keepalive keepalive_opts;
91 keepalive_opts.onoff = keepalive_;
92 keepalive_opts.keepalivetime =
93 keepalive_idle_ != -1 ? keepalive_idle_ * 1000 : 7200000;
94 keepalive_opts.keepaliveinterval =
95 keepalive_intvl_ != -1 ? keepalive_intvl_ * 1000 : 1000;
96 DWORD num_bytes_returned;
97 const int rc = WSAIoctl (
s_, SIO_KEEPALIVE_VALS, &keepalive_opts,
98 sizeof (keepalive_opts),
NULL, 0,
101 if (rc == SOCKET_ERROR)
105 #ifdef ZMQ_HAVE_SO_KEEPALIVE
106 if (keepalive_ != -1) {
108 setsockopt (
s_, SOL_SOCKET, SO_KEEPALIVE,
109 reinterpret_cast<char *
> (&keepalive_),
sizeof (
int));
114 #ifdef ZMQ_HAVE_TCP_KEEPCNT
115 if (keepalive_cnt_ != -1) {
116 int rc = setsockopt (
s_, IPPROTO_TCP, TCP_KEEPCNT, &keepalive_cnt_,
122 #endif // ZMQ_HAVE_TCP_KEEPCNT
124 #ifdef ZMQ_HAVE_TCP_KEEPIDLE
125 if (keepalive_idle_ != -1) {
126 int rc = setsockopt (
s_, IPPROTO_TCP, TCP_KEEPIDLE,
127 &keepalive_idle_,
sizeof (
int));
132 #else // ZMQ_HAVE_TCP_KEEPIDLE
133 #ifdef ZMQ_HAVE_TCP_KEEPALIVE
134 if (keepalive_idle_ != -1) {
135 int rc = setsockopt (
s_, IPPROTO_TCP, TCP_KEEPALIVE,
136 &keepalive_idle_,
sizeof (
int));
141 #endif // ZMQ_HAVE_TCP_KEEPALIVE
142 #endif // ZMQ_HAVE_TCP_KEEPIDLE
144 #ifdef ZMQ_HAVE_TCP_KEEPINTVL
145 if (keepalive_intvl_ != -1) {
146 int rc = setsockopt (
s_, IPPROTO_TCP, TCP_KEEPINTVL,
147 &keepalive_intvl_,
sizeof (
int));
152 #endif // ZMQ_HAVE_TCP_KEEPINTVL
154 #endif // ZMQ_HAVE_SO_KEEPALIVE
155 #endif // ZMQ_HAVE_WINDOWS
167 #if defined(ZMQ_HAVE_WINDOWS) && defined(TCP_MAXRT)
171 setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT,
172 reinterpret_cast<char *
> (&timeout_),
sizeof (timeout_));
176 #elif defined(TCP_USER_TIMEOUT)
177 int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_,
188 #ifdef ZMQ_HAVE_WINDOWS
190 const int nbytes =
send (
s_, (
char *)
data_,
static_cast<int> (size_), 0);
194 const int last_error = WSAGetLastError ();
195 if (nbytes == SOCKET_ERROR && last_error == WSAEWOULDBLOCK)
199 if (nbytes == SOCKET_ERROR
200 && (last_error == WSAENETDOWN || last_error == WSAENETRESET
201 || last_error == WSAEHOSTUNREACH || last_error == WSAECONNABORTED
202 || last_error == WSAETIMEDOUT || last_error == WSAECONNRESET))
208 if (nbytes == SOCKET_ERROR && last_error == WSAENOBUFS)
211 wsa_assert (nbytes != SOCKET_ERROR);
215 ssize_t nbytes =
send (
s_,
static_cast<const char *
> (
data_), size_, 0);
226 #if !defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE
240 return static_cast<int> (nbytes);
247 #ifdef ZMQ_HAVE_WINDOWS
250 recv (
s_,
static_cast<char *
> (
data_),
static_cast<int> (size_), 0);
254 if (rc == SOCKET_ERROR) {
255 const int last_error = WSAGetLastError ();
256 if (last_error == WSAEWOULDBLOCK) {
260 last_error == WSAENETDOWN || last_error == WSAENETRESET
261 || last_error == WSAECONNABORTED || last_error == WSAETIMEDOUT
262 || last_error == WSAECONNRESET || last_error == WSAECONNREFUSED
263 || last_error == WSAENOTCONN || last_error == WSAENOBUFS);
264 errno = wsa_error_to_errno (last_error);
268 return rc == SOCKET_ERROR ? -1 : rc;
272 const ssize_t rc = recv (
s_,
static_cast<char *
> (
data_), size_, 0);
278 #if !defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE
288 return static_cast<int> (rc);
295 #if defined ZMQ_HAVE_WINDOWS && defined SIO_LOOPBACK_FAST_PATH
296 int sio_loopback_fastpath = 1;
297 DWORD number_of_bytes_returned = 0;
299 const int rc = WSAIoctl (
300 socket_, SIO_LOOPBACK_FAST_PATH, &sio_loopback_fastpath,
301 sizeof sio_loopback_fastpath,
NULL, 0, &number_of_bytes_returned, 0, 0);
303 if (SOCKET_ERROR == rc) {
304 const DWORD last_error = ::WSAGetLastError ();
306 if (WSAEOPNOTSUPP == last_error) {
319 #if defined(ZMQ_HAVE_BUSY_POLL)
320 if (busy_poll_ > 0) {
322 setsockopt (socket_, SOL_SOCKET, SO_BUSY_POLL,
323 reinterpret_cast<char *
> (&busy_poll_),
sizeof (
int));
335 bool fallback_to_ipv4_,
350 rc = out_tcp_addr_->
resolve (address_, local_,
false);
363 if (out_tcp_addr_->
family () == AF_INET6)
379 if (!
options_.bound_device.empty ())
381 goto setsockopt_error;
395 #ifdef ZMQ_HAVE_WINDOWS
397 wsa_assert (rc != SOCKET_ERROR);