libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
test_getsockopt_memset.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3  This file is part of libzmq, the ZeroMQ core engine in C++.
4  libzmq is free software; you can redistribute it and/or modify it under
5  the terms of the GNU Lesser General Public License (LGPL) as published
6  by the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  As a special exception, the Contributors give you permission to link
9  this library with independent modules to produce an executable,
10  regardless of the license terms of these independent modules, and to
11  copy and distribute the resulting executable under terms of your choice,
12  provided that you also meet, for each linked independent module, the
13  terms and conditions of the license of that module. An independent
14  module is a module which is not derived from or based on this library.
15  If you modify this library, you must extend this exception to your
16  version of the library.
17  libzmq is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  License for more details.
21  You should have received a copy of the GNU Lesser General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "testutil.hpp"
26 
27 int main (void)
28 {
29  int64_t more;
30  size_t more_size = sizeof(more);
31 
33  void *ctx = zmq_ctx_new ();
34  assert (ctx);
35 
36  void *sb = zmq_socket (ctx, ZMQ_PUB);
37  assert (sb);
38  int rc = zmq_bind (sb, "inproc://a");
39  assert (rc == 0);
40 
41  void *sc = zmq_socket (ctx, ZMQ_SUB);
42  assert (sc);
43  rc = zmq_connect (sc, "inproc://a");
44  assert (rc == 0);
45 
46  memset(&more, 0xFF, sizeof(int64_t));
47  zmq_getsockopt(sc, ZMQ_RCVMORE, &more, &more_size);
48  assert (more_size == sizeof(int));
49  assert (more == 0);
50 
51 
52  // Cleanup
53 
54  rc = zmq_close (sc);
55  assert (rc == 0);
56 
57  rc = zmq_close (sb);
58  assert (rc == 0);
59 
60  rc = zmq_ctx_term (ctx);
61  assert (rc == 0);
62 
63  return 0 ;
64 }
ZMQ_EXPORT void * zmq_ctx_new(void)
Definition: zmq.cpp:115
#define ZMQ_SUB
Definition: zmq.h:248
void setup_test_environment(void)
Definition: testutil.hpp:285
#define ZMQ_PUB
Definition: zmq.h:247
ZMQ_EXPORT void * zmq_socket(void *, int type)
Definition: zmq.cpp:244
ZMQ_EXPORT int zmq_getsockopt(void *s, int option, void *optval, size_t *optvallen)
Definition: zmq.cpp:277
ZMQ_EXPORT int zmq_connect(void *s, const char *addr)
Definition: zmq.cpp:332
ZMQ_EXPORT int zmq_close(void *s)
Definition: zmq.cpp:255
#define ZMQ_RCVMORE
Definition: zmq.h:272
ZMQ_EXPORT int zmq_bind(void *s, const char *addr)
Definition: zmq.cpp:321
int main(void)
ZMQ_EXPORT int zmq_ctx_term(void *context)
Definition: zmq.cpp:162