Created
October 27, 2016 19:12
-
-
Save cxreg/d2b9b5e35019b0fb05dbfc8853f9896c to your computer and use it in GitHub Desktop.
zmq crash, without curve
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
:::::::::::::: | |
server.c | |
:::::::::::::: | |
// invoked as valgrind ./server | |
#include <zmq.h> | |
void main(void) { | |
void *ctx = zmq_ctx_new(); | |
void *socket = zmq_socket(ctx, ZMQ_XPUB); | |
zmq_bind(socket, "tcp://*:9999"); | |
while (1) { | |
char buf[256]; | |
zmq_recv(socket, buf, 256, 0); | |
} | |
} | |
:::::::::::::: | |
client.c | |
:::::::::::::: | |
// run as: while ./client; do :; done | |
#include <zmq.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
// Magic constant, needs to be sufficient time to get the server processing the | |
// subscription but then exit before it's done. This value was narrowed down | |
// based on the behavior of my computer and with the server running in valgrind | |
#define DELAY 2800 | |
void main(void) { | |
void *ctx = zmq_ctx_new(); | |
void *socket = zmq_socket(ctx, ZMQ_SUB); | |
char *sub = "subscription"; | |
zmq_connect(socket, "tcp://localhost:9999"); | |
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, sub, strlen(sub)); | |
usleep(rand() % DELAY); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment