libzmq/tests/test_setsockopt.cpp
Pieter Hintjens 62c66ae7f7 Problem: test_large_msg kills my system temporarily
And I'm on a reasonably sized laptop. I think allocating INT_MAX
memory is dangerous in a test case.

Solution: expose this as a context option. I've used ZMQ_MAX_MSGSZ
and documented it and implemented the API. However I don't know how
to get the parent context for a socket, so the code in zmq.cpp is
still unfinished.
2016-02-09 10:55:09 +01:00

106 lines
2.4 KiB
C++

#include "testutil.hpp"
void test_setsockopt_tcp_recv_buffer (void)
{
int rc;
void *ctx = zmq_ctx_new ();
void *socket = zmq_socket (ctx, ZMQ_PUSH);
int val = 0;
size_t placeholder = sizeof (val);
rc = zmq_getsockopt (socket, ZMQ_RCVBUF, &val, &placeholder);
assert (rc == 0);
assert (val == 8192);
rc = zmq_setsockopt (socket, ZMQ_RCVBUF, &val, sizeof (val));
assert (rc == 0);
assert (val == 8192);
rc = zmq_getsockopt (socket, ZMQ_RCVBUF, &val, &placeholder);
assert (rc == 0);
assert (val == 8192);
val = 16384;
rc = zmq_setsockopt (socket, ZMQ_RCVBUF, &val, sizeof (val));
assert (rc == 0);
assert (val == 16384);
rc = zmq_getsockopt (socket, ZMQ_RCVBUF, &val, &placeholder);
assert (rc == 0);
assert (val == 16384);
zmq_close (socket);
zmq_ctx_term (ctx);
}
void test_setsockopt_tcp_send_buffer (void)
{
int rc;
void *ctx = zmq_ctx_new ();
void *socket = zmq_socket (ctx, ZMQ_PUSH);
int val = 0;
size_t placeholder = sizeof (val);
rc = zmq_getsockopt (socket, ZMQ_SNDBUF, &val, &placeholder);
assert (rc == 0);
assert (val == 8192);
rc = zmq_setsockopt (socket, ZMQ_SNDBUF, &val, sizeof (val));
assert (rc == 0);
assert (val == 8192);
rc = zmq_getsockopt (socket, ZMQ_SNDBUF, &val, &placeholder);
assert (rc == 0);
assert (val == 8192);
val = 16384;
rc = zmq_setsockopt (socket, ZMQ_SNDBUF, &val, sizeof (val));
assert (rc == 0);
assert (val == 16384);
rc = zmq_getsockopt (socket, ZMQ_SNDBUF, &val, &placeholder);
assert (rc == 0);
assert (val == 16384);
zmq_close (socket);
zmq_ctx_term (ctx);
}
void test_setsockopt_use_fd ()
{
int rc;
void *ctx = zmq_ctx_new ();
void *socket = zmq_socket (ctx, ZMQ_PUSH);
int val = 0;
size_t placeholder = sizeof (val);
rc = zmq_getsockopt (socket, ZMQ_USE_FD, &val, &placeholder);
assert(rc == 0);
assert(val == -1);
val = 3;
rc = zmq_setsockopt (socket, ZMQ_USE_FD, &val, sizeof(val));
assert(rc == 0);
assert(val == 3);
rc = zmq_getsockopt (socket, ZMQ_USE_FD, &val, &placeholder);
assert(rc == 0);
assert(val == 3);
zmq_close (socket);
zmq_ctx_term (ctx);
}
int main (void)
{
test_setsockopt_tcp_recv_buffer ();
test_setsockopt_tcp_send_buffer ();
test_setsockopt_use_fd ();
}