-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C code to illustrate issue LIBZMQ-256 problem with IDENTITY
- Loading branch information
Chuck Remes
committed
Sep 17, 2011
1 parent
a634396
commit a172a19
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
To avoid loading a system-wide 0mq library, place | ||
the C libraries here. This let's you run your Ruby | ||
code with a 0mq C library build that is different | ||
from the system-wide one. This can be handy for | ||
rolling upgrades or testing. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Custom IDENTITY values are not preserved as | ||
// they are passed from one socket to another. | ||
// | ||
// gcc -lzmq issue.c | ||
// chmod +x a.out | ||
// ./a.out | ||
// | ||
#include <zmq.h> | ||
|
||
|
||
// several of these are probably unnecessary... | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <string.h> | ||
#include <sys/time.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
#include <assert.h> | ||
#include <inttypes.h> | ||
|
||
|
||
|
||
int main (void) | ||
{ | ||
int rc; | ||
void *context = zmq_init (1); | ||
void *sender = zmq_socket (context, ZMQ_REQ); | ||
void *receiver = zmq_socket (context, ZMQ_XREP); | ||
|
||
// set a custom IDENTITY | ||
assert (0 == zmq_setsockopt (sender, ZMQ_IDENTITY, "Custom", 6)); | ||
assert (0 == zmq_bind (receiver, "tcp://127.0.0.1:7557")); | ||
assert (0 == zmq_connect (sender, "tcp://127.0.0.1:7557")); | ||
|
||
zmq_msg_t m1, m2; | ||
assert (0 == zmq_msg_init_data (&m1, "Hello world", 11, NULL, NULL)); | ||
assert (11 == zmq_sendmsg(sender, &m1, 0)); | ||
|
||
assert (0 == zmq_msg_init (&m2) ); | ||
assert (-1 != zmq_recvmsg (receiver, &m2, 0)); | ||
|
||
int label, more; | ||
size_t size = sizeof (label); | ||
|
||
do { | ||
assert (0 == zmq_msg_init (&m2)); | ||
assert (-1 != zmq_recvmsg (receiver, &m2, 0)); | ||
assert (0 == zmq_getsockopt (receiver, ZMQ_RCVLABEL, &label, &size)); | ||
assert (0 == zmq_getsockopt (receiver, ZMQ_RCVMORE, &more, &size)); | ||
|
||
if (label) | ||
printf ("LABEL (should be 'Custom'): %s\n", (char*) zmq_msg_data (&m2)); | ||
else | ||
printf ("Contents: %s\n", (char*) zmq_msg_data (&m2)); | ||
} | ||
while ( (label == 1) || (more == 1)); | ||
|
||
zmq_close (sender); | ||
zmq_close (receiver); | ||
zmq_term (context); | ||
return (0); | ||
} |