2
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
4
This file is part of 0MQ.
6
0MQ is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
0MQ is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "testutil.hpp"
22
static void receiver (void *socket)
25
int rc = zmq_recv (socket, &buffer, sizeof (buffer), 0);
29
void test_ctx_destroy()
33
// Set up our context and sockets
34
void *ctx = zmq_ctx_new ();
37
void *socket = zmq_socket (ctx, ZMQ_PULL);
41
rc = zmq_close (socket);
44
// Destroy the context
45
rc = zmq_ctx_destroy (ctx);
49
void test_ctx_shutdown()
53
// Set up our context and sockets
54
void *ctx = zmq_ctx_new ();
57
void *socket = zmq_socket (ctx, ZMQ_PULL);
60
// Spawn a thread to receive on socket
61
void *receiver_thread = zmq_threadstart (&receiver, socket);
63
// Wait for thread to start up and block
66
// Shutdown context, if we used destroy here we would deadlock.
67
rc = zmq_ctx_shutdown (ctx);
70
// Wait for thread to finish
71
zmq_threadclose (receiver_thread);
74
rc = zmq_close (socket);
77
// Destory the context, will now not hang as we have closed the socket.
78
rc = zmq_ctx_destroy (ctx);
84
setup_test_environment();