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
6
This file is part of 0MQ.
8
0MQ is free software; you can redistribute it and/or modify it under
9
the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
13
0MQ is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
25
#include "platform.hpp"
27
#if defined ZMQ_HAVE_WINDOWS
28
#include "windows.hpp"
31
#include <sys/types.h>
32
#include <sys/socket.h>
33
#include <netinet/in.h>
34
#include <netinet/tcp.h>
37
#if defined ZMQ_HAVE_OPENVMS
41
void zmq::tune_tcp_socket (fd_t s_)
43
// Disable Nagle's algorithm. We are doing data batching on 0MQ level,
44
// so using Nagle wouldn't improve throughput in anyway, but it would
47
int rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
49
#ifdef ZMQ_HAVE_WINDOWS
50
wsa_assert (rc != SOCKET_ERROR);
52
errno_assert (rc == 0);
55
#ifdef ZMQ_HAVE_OPENVMS
56
// Disable delayed acknowledgements as they hurt latency is serious manner.
58
rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
60
errno_assert (rc != SOCKET_ERROR);
64
void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int keepalive_idle_, int keepalive_intvl_)
66
// These options are used only under certain #ifdefs below.
69
(void)keepalive_idle_;
70
(void)keepalive_intvl_;
72
// If none of the #ifdefs apply, then s_ is unused.
75
// Tuning TCP keep-alives if platform allows it
76
// All values = -1 means skip and leave it for OS
77
#ifdef ZMQ_HAVE_SO_KEEPALIVE
78
if (keepalive_ != -1) {
79
int rc = setsockopt (s_, SOL_SOCKET, SO_KEEPALIVE, (char*) &keepalive_, sizeof (int));
80
#ifdef ZMQ_HAVE_WINDOWS
81
wsa_assert (rc != SOCKET_ERROR);
83
errno_assert (rc == 0);
86
#ifdef ZMQ_HAVE_TCP_KEEPCNT
87
if (keepalive_cnt_ != -1) {
88
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPCNT, &keepalive_cnt_, sizeof (int));
89
#ifdef ZMQ_HAVE_WINDOWS
90
wsa_assert (rc != SOCKET_ERROR);
92
errno_assert (rc == 0);
95
#endif // ZMQ_HAVE_TCP_KEEPCNT
97
#ifdef ZMQ_HAVE_TCP_KEEPIDLE
98
if (keepalive_idle_ != -1) {
99
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_idle_, sizeof (int));
100
#ifdef ZMQ_HAVE_WINDOWS
101
wsa_assert (rc != SOCKET_ERROR);
103
errno_assert (rc == 0);
106
#else // ZMQ_HAVE_TCP_KEEPIDLE
107
#ifdef ZMQ_HAVE_TCP_KEEPALIVE
108
if (keepalive_idle_ != -1) {
109
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPALIVE, &keepalive_idle_, sizeof (int));
110
#ifdef ZMQ_HAVE_WINDOWS
111
wsa_assert (rc != SOCKET_ERROR);
113
errno_assert (rc == 0);
116
#endif // ZMQ_HAVE_TCP_KEEPALIVE
117
#endif // ZMQ_HAVE_TCP_KEEPIDLE
119
#ifdef ZMQ_HAVE_TCP_KEEPINTVL
120
if (keepalive_intvl_ != -1) {
121
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl_, sizeof (int));
122
#ifdef ZMQ_HAVE_WINDOWS
123
wsa_assert (rc != SOCKET_ERROR);
125
errno_assert (rc == 0);
128
#endif // ZMQ_HAVE_TCP_KEEPINTVL
130
#endif // ZMQ_HAVE_SO_KEEPALIVE