· 9 years ago · Oct 28, 2016, 04:06 PM
1daveo@abraxas:~/zmq-crash-repro$ more server.c client.c
2::::::::::::::
3server.c
4::::::::::::::
5// invoked as valgrind ./server
6#include <zmq.h>
7
8void main(void) {
9 void *ctx = zmq_ctx_new();
10 void *socket = zmq_socket(ctx, ZMQ_XPUB);
11 int one = 1;
12 char *secret_key = "2).NRO5d[JbEFli7F@hdvE1(Fv?B6iIAn>NcLLDx";
13 zmq_setsockopt(socket, ZMQ_CURVE_SERVER, &one, sizeof(one));
14 zmq_setsockopt(socket, ZMQ_CURVE_SECRETKEY, secret_key, 40);
15 zmq_bind(socket, "tcp://*:9999");
16
17 while (1) {
18 char buf[256];
19 zmq_recv(socket, buf, 256, 0);
20 //if (buf[0] == 1) fprintf(stderr, "got %s\n", buf + 1);
21 }
22}
23::::::::::::::
24client.c
25::::::::::::::
26// run as: while ./client; do :; done
27#include <zmq.h>
28#include <string.h>
29#include <unistd.h>
30#include <stdlib.h>
31
32// Magic constant, needs to be sufficient time to get the server processing
33// the subscription but then exit before it's done. Curve is used only
34// because it adds time and cost to the equation, and probably is not a
35// functioning part of error. This value was narrowed down based on the
36// behavior of my computer and with the server running in valgrind
37#define DELAY 28000
38
39void main(void) {
40 void *ctx = zmq_ctx_new();
41 void *socket = zmq_socket(ctx, ZMQ_SUB);
42 char *sub = "subscription";
43 char public_key[41], private_key[41];
44 char *server_key = "^kvy<i^qI<r{=ZDrfK4K<#NtqY+zaH:ksm/YGE6I";
45 zmq_curve_keypair(public_key, private_key);
46 zmq_setsockopt(socket, ZMQ_CURVE_SERVERKEY, server_key, 40);
47 zmq_setsockopt(socket, ZMQ_CURVE_PUBLICKEY, public_key, 40);
48 zmq_setsockopt(socket, ZMQ_CURVE_SECRETKEY, private_key, 40);
49 zmq_connect(socket, "tcp://localhost:9999");
50 zmq_setsockopt(socket, ZMQ_SUBSCRIBE, sub, strlen(sub));
51 usleep(rand() % DELAY);
52}