Skip to content

Instantly share code, notes, and snippets.

@cxreg
Created October 27, 2016 19:12
Show Gist options
  • Save cxreg/d2b9b5e35019b0fb05dbfc8853f9896c to your computer and use it in GitHub Desktop.
Save cxreg/d2b9b5e35019b0fb05dbfc8853f9896c to your computer and use it in GitHub Desktop.
zmq crash, without curve
::::::::::::::
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