test_ctx_options.cpp 2.88 KB
Newer Older
Pieter Hintjens's avatar
Pieter Hintjens committed
1
/*
2
    Copyright (c) 2007-2015 Contributors as noted in the AUTHORS file
Pieter Hintjens's avatar
Pieter Hintjens committed
3

4
    This file is part of libzmq, the ZeroMQ core engine in C++.
Pieter Hintjens's avatar
Pieter Hintjens committed
5

6 7 8
    libzmq is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 3 of the License, or
Pieter Hintjens's avatar
Pieter Hintjens committed
9 10
    (at your option) any later version.

11 12 13 14 15 16 17 18 19 20 21 22 23 24
    As a special exception, the Contributors give you permission to link
    this library with independent modules to produce an executable,
    regardless of the license terms of these independent modules, and to
    copy and distribute the resulting executable under terms of your choice,
    provided that you also meet, for each linked independent module, the
    terms and conditions of the license of that module. An independent
    module is a module which is not derived from or based on this library.
    If you modify this library, you must extend this exception to your
    version of the library.

    libzmq is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    License for more details.
Pieter Hintjens's avatar
Pieter Hintjens committed
25 26 27 28 29

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

30
#include <limits>
31
#include "testutil.hpp"
Pieter Hintjens's avatar
Pieter Hintjens committed
32 33 34

int main (void)
{
35
    setup_test_environment();
Pieter Hintjens's avatar
Pieter Hintjens committed
36 37 38 39 40 41 42
    int rc;
    
    //  Set up our context and sockets
    void *ctx = zmq_ctx_new ();
    assert (ctx);
    
    assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT);
43
#if defined(ZMQ_USE_SELECT)
44
    assert (zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT) == FD_SETSIZE - 1);
45 46
#elif    defined(ZMQ_USE_POLL) || defined(ZMQ_USE_EPOLL)     \
      || defined(ZMQ_USE_DEVPOLL) || defined(ZMQ_USE_KQUEUE)
47
    assert (zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT) == 65535);
48
#endif
Pieter Hintjens's avatar
Pieter Hintjens committed
49 50 51 52
    assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);
    
    rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
Richard Newton's avatar
Richard Newton committed
53
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 1);
Pieter Hintjens's avatar
Pieter Hintjens committed
54 55
    
    void *router = zmq_socket (ctx, ZMQ_ROUTER);
56
    int value;
Pieter Hintjens's avatar
Pieter Hintjens committed
57
    size_t optsize = sizeof (int);
58
    rc = zmq_getsockopt (router, ZMQ_IPV6, &value, &optsize);
Pieter Hintjens's avatar
Pieter Hintjens committed
59
    assert (rc == 0);
60 61 62 63
    assert (value == 1);
    rc = zmq_getsockopt (router, ZMQ_LINGER, &value, &optsize);
    assert (rc == 0);
    assert (value == -1);
Pieter Hintjens's avatar
Pieter Hintjens committed
64 65 66
    rc = zmq_close (router);
    assert (rc == 0);
    
67 68 69 70 71 72 73 74 75
    rc = zmq_ctx_set (ctx, ZMQ_BLOCKY, false);
    assert (zmq_ctx_get (ctx, ZMQ_BLOCKY) == 0);
    router = zmq_socket (ctx, ZMQ_ROUTER);
    rc = zmq_getsockopt (router, ZMQ_LINGER, &value, &optsize);
    assert (rc == 0);
    assert (value == 0);
    rc = zmq_close (router);
    assert (rc == 0);

Pieter Hintjens's avatar
Pieter Hintjens committed
76 77 78 79 80
    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0;
}