Created
June 11, 2011 14:55
-
-
Save lucsky/1020628 to your computer and use it in GitHub Desktop.
Test case which demonstrates the "Assertion failed: nbytes == sizeof (command_t)" occuring on orderly shutdown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zmq.h> | |
#include <assert.h> | |
#include <signal.h> | |
static void* ctx = NULL; | |
void handle_signal(int sig) | |
{ | |
void* push = zmq_socket(ctx, ZMQ_PUSH); | |
zmq_connect(push, "inproc://CONTROL-SOCKET"); | |
zmq_msg_t message; | |
zmq_msg_init(&message); | |
zmq_send(push, &message, 0); | |
zmq_msg_close(&message); | |
zmq_close(push); | |
} | |
int main(int argc, char const* argv[]) | |
{ | |
// Setup signal handling | |
struct sigaction action; | |
action.sa_handler = handle_signal; | |
action.sa_flags = 0; | |
sigemptyset(&action.sa_mask); | |
sigaction(SIGINT, &action, NULL); | |
sigaction(SIGTERM, &action, NULL); | |
// Setup ZMQ | |
ctx = zmq_init(1); | |
int rc = 0; | |
void* router = zmq_socket(ctx, ZMQ_ROUTER); | |
assert(router != NULL); | |
rc = zmq_bind(router, "tcp://*:4567"); | |
assert(rc == 0); | |
void* puller = zmq_socket(ctx, ZMQ_PULL); | |
assert(puller != NULL); | |
rc = zmq_bind(puller, "inproc://CONTROL-SOCKET"); | |
assert(rc == 0); | |
zmq_pollitem_t poll_item[4]; | |
poll_item[0].socket = puller; | |
poll_item[0].fd = 0; | |
poll_item[0].events = ZMQ_POLLIN; | |
poll_item[0].revents = 0; | |
// Loop | |
int keep_looping = 1; | |
while (keep_looping) | |
{ | |
zmq_poll(poll_item, 1, 100000); | |
if (poll_item[0].revents & ZMQ_POLLIN) | |
{ | |
zmq_msg_t message; | |
zmq_msg_init(&message); | |
zmq_recv(puller, &message, 0); | |
zmq_msg_close(&message); | |
keep_looping = 0; | |
} | |
} | |
// Terminate | |
zmq_close(puller); | |
zmq_close(router); | |
zmq_term(ctx); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment