libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
test_setsockopt.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #include "testutil.hpp"
31 
33 {
34  int rc;
35  void *ctx = zmq_ctx_new ();
36  void *socket = zmq_socket (ctx, ZMQ_PUSH);
37 
38  int val = 0;
39  size_t placeholder = sizeof (val);
40 
41  rc = zmq_getsockopt (socket, ZMQ_RCVBUF, &val, &placeholder);
42  assert (rc == 0);
43  assert (val == -1);
44 
45  val = 16384;
46 
47  rc = zmq_setsockopt (socket, ZMQ_RCVBUF, &val, sizeof (val));
48  assert (rc == 0);
49  assert (val == 16384);
50 
51  rc = zmq_getsockopt (socket, ZMQ_RCVBUF, &val, &placeholder);
52  assert (rc == 0);
53  assert (val == 16384);
54 
55  zmq_close (socket);
56  zmq_ctx_term (ctx);
57 }
58 
60 {
61  int rc;
62  void *ctx = zmq_ctx_new ();
63  void *socket = zmq_socket (ctx, ZMQ_PUSH);
64 
65  int val = 0;
66  size_t placeholder = sizeof (val);
67 
68  rc = zmq_getsockopt (socket, ZMQ_SNDBUF, &val, &placeholder);
69  assert (rc == 0);
70  assert (val == -1);
71 
72  val = 16384;
73 
74  rc = zmq_setsockopt (socket, ZMQ_SNDBUF, &val, sizeof (val));
75  assert (rc == 0);
76  assert (val == 16384);
77 
78  rc = zmq_getsockopt (socket, ZMQ_SNDBUF, &val, &placeholder);
79  assert (rc == 0);
80  assert (val == 16384);
81 
82  zmq_close (socket);
83  zmq_ctx_term (ctx);
84 }
85 
87 {
88  int rc;
89  void *ctx = zmq_ctx_new ();
90  void *socket = zmq_socket (ctx, ZMQ_PUSH);
91 
92  int val = 0;
93  size_t placeholder = sizeof (val);
94 
95  rc = zmq_getsockopt (socket, ZMQ_USE_FD, &val, &placeholder);
96  assert(rc == 0);
97  assert(val == -1);
98 
99  val = 3;
100 
101  rc = zmq_setsockopt (socket, ZMQ_USE_FD, &val, sizeof(val));
102  assert(rc == 0);
103  assert(val == 3);
104 
105  rc = zmq_getsockopt (socket, ZMQ_USE_FD, &val, &placeholder);
106  assert(rc == 0);
107  assert(val == 3);
108 
109  zmq_close (socket);
110  zmq_ctx_term (ctx);
111 }
112 
113 int main (void)
114 {
118 }
ZMQ_EXPORT int zmq_setsockopt(void *s, int option, const void *optval, size_t optvallen)
Definition: zmq.cpp:265
ZMQ_EXPORT void * zmq_ctx_new(void)
Definition: zmq.cpp:115
#define ZMQ_SNDBUF
Definition: zmq.h:270
void test_setsockopt_tcp_recv_buffer(void)
#define ZMQ_RCVBUF
Definition: zmq.h:271
ZMQ_EXPORT void * zmq_socket(void *, int type)
Definition: zmq.cpp:244
#define ZMQ_PUSH
Definition: zmq.h:254
ZMQ_EXPORT int zmq_getsockopt(void *s, int option, void *optval, size_t *optvallen)
Definition: zmq.cpp:277
ZMQ_EXPORT int zmq_close(void *s)
Definition: zmq.cpp:255
#define ZMQ_USE_FD
Definition: zmq.h:338
int main(void)
ZMQ_EXPORT int zmq_ctx_term(void *context)
Definition: zmq.cpp:162
void test_setsockopt_tcp_send_buffer(void)
void test_setsockopt_use_fd()