mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 18:55:10 +01:00
4bcbb3055e
Solution: add new [set|get]sockopt ZMQ_PRE_ALLOCATED_FD to allow users to let ZMQ use a pre-allocated file descriptor instead of allocating a new one. Update [set|get]sockopt documentation and test accordingly. The main use case for this feature is a socket-activated systemd service. For more information about this feature see: http://0pointer.de/blog/projects/socket-activation.html
107 lines
2.4 KiB
C++
107 lines
2.4 KiB
C++
#include "testutil.hpp"
|
|
|
|
void test_setsockopt_tcp_recv_buffer()
|
|
{
|
|
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_TCP_RECV_BUFFER, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 8192);
|
|
|
|
rc = zmq_setsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, sizeof(val));
|
|
assert(rc == 0);
|
|
assert(val == 8192);
|
|
|
|
rc = zmq_getsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 8192);
|
|
|
|
val = 16384;
|
|
|
|
rc = zmq_setsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, sizeof(val));
|
|
assert(rc == 0);
|
|
assert(val == 16384);
|
|
|
|
rc = zmq_getsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 16384);
|
|
|
|
zmq_close(socket);
|
|
zmq_ctx_term(ctx);
|
|
}
|
|
|
|
void test_setsockopt_tcp_send_buffer()
|
|
{
|
|
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_TCP_SEND_BUFFER, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 8192);
|
|
|
|
rc = zmq_setsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, sizeof(val));
|
|
assert(rc == 0);
|
|
assert(val == 8192);
|
|
|
|
rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 8192);
|
|
|
|
val = 16384;
|
|
|
|
rc = zmq_setsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, sizeof(val));
|
|
assert(rc == 0);
|
|
assert(val == 16384);
|
|
|
|
rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 16384);
|
|
|
|
zmq_close(socket);
|
|
zmq_ctx_term(ctx);
|
|
}
|
|
|
|
void test_setsockopt_pre_allocated_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_PRE_ALLOCATED_FD, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == -1);
|
|
|
|
val = 3;
|
|
|
|
rc = zmq_setsockopt(socket, ZMQ_PRE_ALLOCATED_FD, &val, sizeof(val));
|
|
assert(rc == 0);
|
|
assert(val == 3);
|
|
|
|
rc = zmq_getsockopt(socket, ZMQ_PRE_ALLOCATED_FD, &val, &placeholder);
|
|
assert(rc == 0);
|
|
assert(val == 3);
|
|
|
|
zmq_close(socket);
|
|
zmq_ctx_term(ctx);
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
test_setsockopt_tcp_recv_buffer();
|
|
test_setsockopt_tcp_send_buffer();
|
|
test_setsockopt_pre_allocated_fd();
|
|
}
|