Commit 17e82a36 authored by Martin Sustrik's avatar Martin Sustrik

ZMQ_SNDBUF and ZMQ_RCVBUF type changed to int

This mimics POSIX specification.
Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent a2252de2
......@@ -159,7 +159,7 @@ in effect. For details refer to your operating system documentation for the
'SO_SNDBUF' socket option.
[horizontal]
Option value type:: uint64_t
Option value type:: int
Option value unit:: bytes
Default value:: 0
Applicable socket types:: all
......@@ -173,7 +173,7 @@ in effect. For details refer to your operating system documentation for the
'SO_RCVBUF' socket option.
[horizontal]
Option value type:: uint64_t
Option value type:: int
Option value unit:: bytes
Default value:: 0
Applicable socket types:: all
......
......@@ -164,7 +164,7 @@ the OS default unchanged. For details please refer to your operating system
documentation for the 'SO_SNDBUF' socket option.
[horizontal]
Option value type:: uint64_t
Option value type:: int
Option value unit:: bytes
Default value:: 0
Applicable socket types:: all
......@@ -178,7 +178,7 @@ OS default unchanged. For details refer to your operating system documentation
for the 'SO_RCVBUF' socket option.
[horizontal]
Option value type:: uint64_t
Option value type:: int
Option value unit:: bytes
Default value:: 0
Applicable socket types:: all
......
......@@ -87,7 +87,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
return 0;
case ZMQ_RECOVERY_IVL:
if (optvallen_ != sizeof (int64_t) || *((int64_t*) optval_) < 0) {
if (optvallen_ != sizeof (int64_t) || *((int64_t*) optval_) < 0) {
errno = EINVAL;
return -1;
}
......@@ -95,19 +95,19 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
return 0;
case ZMQ_SNDBUF:
if (optvallen_ != sizeof (uint64_t)) {
if (optvallen_ != sizeof (int) || *((int*) optval_) < 0) {
errno = EINVAL;
return -1;
}
sndbuf = *((uint64_t*) optval_);
sndbuf = *((int*) optval_);
return 0;
case ZMQ_RCVBUF:
if (optvallen_ != sizeof (uint64_t)) {
if (optvallen_ != sizeof (int) || *((int*) optval_) < 0) {
errno = EINVAL;
return -1;
}
rcvbuf = *((uint64_t*) optval_);
rcvbuf = *((int*) optval_);
return 0;
case ZMQ_LINGER:
......@@ -215,21 +215,21 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
return 0;
case ZMQ_SNDBUF:
if (*optvallen_ < sizeof (uint64_t)) {
if (*optvallen_ < sizeof (int)) {
errno = EINVAL;
return -1;
}
*((uint64_t*) optval_) = sndbuf;
*optvallen_ = sizeof (uint64_t);
*((int*) optval_) = sndbuf;
*optvallen_ = sizeof (int);
return 0;
case ZMQ_RCVBUF:
if (*optvallen_ < sizeof (uint64_t)) {
if (*optvallen_ < sizeof (int)) {
errno = EINVAL;
return -1;
}
*((uint64_t*) optval_) = rcvbuf;
*optvallen_ = sizeof (uint64_t);
*((int*) optval_) = rcvbuf;
*optvallen_ = sizeof (int);
return 0;
case ZMQ_TYPE:
......
......@@ -45,8 +45,9 @@ namespace zmq
// Reliability time interval [ms]. Default 10 seconds.
uint32_t recovery_ivl;
uint64_t sndbuf;
uint64_t rcvbuf;
// SO_SNDBUF and SO_RCVBUF to be passed to underlying transport sockets.
int sndbuf;
int rcvbuf;
// Socket type.
int type;
......
......@@ -35,22 +35,21 @@ zmq::tcp_socket_t::~tcp_socket_t ()
close ();
}
int zmq::tcp_socket_t::open (fd_t fd_, uint64_t sndbuf_, uint64_t rcvbuf_)
int zmq::tcp_socket_t::open (fd_t fd_, int sndbuf_, int rcvbuf_)
{
zmq_assert (s == retired_fd);
s = fd_;
if (sndbuf_) {
int sz = (int) sndbuf_;
int rc = setsockopt (s, SOL_SOCKET, SO_SNDBUF,
(char*) &sz, sizeof (int));
(char*) &sndbuf_, sizeof (int));
errno_assert (rc == 0);
}
if (rcvbuf_) {
int sz = (int) rcvbuf_;
int rc = setsockopt (s, SOL_SOCKET, SO_RCVBUF,
(char*) &sz, sizeof (int));
(char*) &rcvbuf_, sizeof (int));
errno_assert (rc == 0);
}
......@@ -145,20 +144,18 @@ zmq::tcp_socket_t::~tcp_socket_t ()
close ();
}
int zmq::tcp_socket_t::open (fd_t fd_, uint64_t sndbuf_, uint64_t rcvbuf_)
int zmq::tcp_socket_t::open (fd_t fd_, int sndbuf_, int rcvbuf_)
{
assert (s == retired_fd);
s = fd_;
if (sndbuf_) {
int sz = (int) sndbuf_;
int rc = setsockopt (s, SOL_SOCKET, SO_SNDBUF, &sz, sizeof (int));
int rc = setsockopt (s, SOL_SOCKET, SO_SNDBUF, &sndbuf_, sizeof (int));
errno_assert (rc == 0);
}
if (rcvbuf_) {
int sz = (int) rcvbuf_;
int rc = setsockopt (s, SOL_SOCKET, SO_RCVBUF, &sz, sizeof (int));
int rc = setsockopt (s, SOL_SOCKET, SO_RCVBUF, &rcvbuf_, sizeof (int));
errno_assert (rc == 0);
}
......
......@@ -37,7 +37,7 @@ namespace zmq
~tcp_socket_t ();
// Associates a socket with a native socket descriptor.
int open (fd_t fd_, uint64_t sndbuf_, uint64_t rcvbuf_);
int open (fd_t fd_, int sndbuf_, int rcvbuf_);
// Closes the underlying socket.
int close ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment