~ubuntu-branches/ubuntu/wily/zeromq3/wily-proposed

« back to all changes in this revision

Viewing changes to src/tcp.cpp

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2014-03-16 14:02:28 UTC
  • mfrom: (1.1.6) (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140316140228-ig1sgh7czk59m9ux
Tags: 4.0.4+dfsg-1
* QA upload; orphan the package
  - Upload to unstable
* New upstream release
* Update repack.stub script
* Drop 02_fix-exported-symbols.patch and 03_fix-s390-rdtsc.patch
  (merged upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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
5
3
 
6
4
    This file is part of 0MQ.
7
5
 
61
59
#endif
62
60
}
63
61
 
 
62
void zmq::set_tcp_send_buffer (fd_t sockfd_, int bufsize_)
 
63
{
 
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);
 
68
#else
 
69
    errno_assert (rc == 0);
 
70
#endif
 
71
}
 
72
 
 
73
void zmq::set_tcp_receive_buffer (fd_t sockfd_, int bufsize_)
 
74
{
 
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);
 
79
#else
 
80
    errno_assert (rc == 0);
 
81
#endif
 
82
}
 
83
 
64
84
void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int keepalive_idle_, int keepalive_intvl_)
65
85
{
66
86
    // These options are used only under certain #ifdefs below.
74
94
 
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);
 
105
#else
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);
82
 
#else
83
109
        errno_assert (rc == 0);
84
 
#endif
85
110
 
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);
91
 
#else
92
114
            errno_assert (rc == 0);
93
 
#endif
94
115
        }
95
116
#endif // ZMQ_HAVE_TCP_KEEPCNT
96
117
 
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);
102
 
#else
103
121
            errno_assert (rc == 0);
104
 
#endif
105
122
        }
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);
112
 
#else
113
127
            errno_assert (rc == 0);
114
 
#endif
115
128
        }
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);
124
 
#else
125
135
            errno_assert (rc == 0);
126
 
#endif
127
136
        }
128
137
#endif // ZMQ_HAVE_TCP_KEEPINTVL
129
138
    }
130
139
#endif // ZMQ_HAVE_SO_KEEPALIVE
 
140
#endif // ZMQ_HAVE_WINDOWS
131
141
}