2
Copyright (c) 2010-2011 250bpm s.r.o.
3
Copyright (c) 2007-2009 iMatix Corporation
4
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
2
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
6
4
This file is part of 0MQ.
62
void zmq::set_tcp_send_buffer (fd_t sockfd_, int bufsize_)
64
const int rc = setsockopt (sockfd_, SOL_SOCKET, SO_SNDBUF,
65
(char*) &bufsize_, sizeof bufsize_);
66
#ifdef ZMQ_HAVE_WINDOWS
67
wsa_assert (rc != SOCKET_ERROR);
69
errno_assert (rc == 0);
73
void zmq::set_tcp_receive_buffer (fd_t sockfd_, int bufsize_)
75
const int rc = setsockopt (sockfd_, SOL_SOCKET, SO_RCVBUF,
76
(char*) &bufsize_, sizeof bufsize_);
77
#ifdef ZMQ_HAVE_WINDOWS
78
wsa_assert (rc != SOCKET_ERROR);
80
errno_assert (rc == 0);
64
84
void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int keepalive_idle_, int keepalive_intvl_)
66
86
// These options are used only under certain #ifdefs below.
75
95
// Tuning TCP keep-alives if platform allows it
76
96
// All values = -1 means skip and leave it for OS
97
#ifdef ZMQ_HAVE_WINDOWS
98
tcp_keepalive keepalive_opts;
99
keepalive_opts.onoff = keepalive_;
100
keepalive_opts.keepalivetime = keepalive_idle_ != -1 ? keepalive_idle_ * 1000 : 7200000;
101
keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ? keepalive_intvl_ * 1000 : 1000;
102
DWORD num_bytes_returned;
103
int rc = WSAIoctl(s_, SIO_KEEPALIVE_VALS, &keepalive_opts, sizeof(keepalive_opts), NULL, 0, &num_bytes_returned, NULL, NULL);
104
wsa_assert (rc != SOCKET_ERROR);
77
106
#ifdef ZMQ_HAVE_SO_KEEPALIVE
78
107
if (keepalive_ != -1) {
79
108
int rc = setsockopt (s_, SOL_SOCKET, SO_KEEPALIVE, (char*) &keepalive_, sizeof (int));
80
#ifdef ZMQ_HAVE_WINDOWS
81
wsa_assert (rc != SOCKET_ERROR);
83
109
errno_assert (rc == 0);
86
111
#ifdef ZMQ_HAVE_TCP_KEEPCNT
87
112
if (keepalive_cnt_ != -1) {
88
113
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPCNT, &keepalive_cnt_, sizeof (int));
89
#ifdef ZMQ_HAVE_WINDOWS
90
wsa_assert (rc != SOCKET_ERROR);
92
114
errno_assert (rc == 0);
95
116
#endif // ZMQ_HAVE_TCP_KEEPCNT
97
118
#ifdef ZMQ_HAVE_TCP_KEEPIDLE
98
119
if (keepalive_idle_ != -1) {
99
120
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_idle_, sizeof (int));
100
#ifdef ZMQ_HAVE_WINDOWS
101
wsa_assert (rc != SOCKET_ERROR);
103
121
errno_assert (rc == 0);
106
123
#else // ZMQ_HAVE_TCP_KEEPIDLE
107
124
#ifdef ZMQ_HAVE_TCP_KEEPALIVE
108
125
if (keepalive_idle_ != -1) {
109
126
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPALIVE, &keepalive_idle_, sizeof (int));
110
#ifdef ZMQ_HAVE_WINDOWS
111
wsa_assert (rc != SOCKET_ERROR);
113
127
errno_assert (rc == 0);
116
129
#endif // ZMQ_HAVE_TCP_KEEPALIVE
117
130
#endif // ZMQ_HAVE_TCP_KEEPIDLE
119
132
#ifdef ZMQ_HAVE_TCP_KEEPINTVL
120
133
if (keepalive_intvl_ != -1) {
121
134
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl_, sizeof (int));
122
#ifdef ZMQ_HAVE_WINDOWS
123
wsa_assert (rc != SOCKET_ERROR);
125
135
errno_assert (rc == 0);
128
137
#endif // ZMQ_HAVE_TCP_KEEPINTVL
130
139
#endif // ZMQ_HAVE_SO_KEEPALIVE
140
#endif // ZMQ_HAVE_WINDOWS