Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 1134/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This test shows issue with ZMQ_PAIR socket when client connects to server in a loop, sends message and closes socket.
Result of execution: client hangs in zmq_send function after sending a few messages.

Compilation command:
gcc issue.c -lzmq -lpthread
51 changes: 51 additions & 0 deletions 1134/issue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <zmq.h>
#include <pthread.h>
#include <string.h>
#include <assert.h>

static void* client(void *context)
{
int request_index = 0;
while (1)
{
int rc;
void *sender = zmq_socket (context, ZMQ_PAIR);
rc = zmq_connect (sender, "inproc://identity");
assert(rc != -1);
char buffer [256];
sprintf(buffer, "message [%d]", request_index);
rc = zmq_send (sender, buffer, strlen(buffer) + 1, 0);
assert(rc != -1);
request_index++;
int linger = 0;
zmq_setsockopt(sender, ZMQ_LINGER, &linger, sizeof(int));
rc = zmq_close (sender);
assert (rc != -1);
}
}

static void* server(void *context)
{
void *receiver = zmq_socket (context, ZMQ_PAIR);
zmq_bind (receiver, "inproc://identity");
while (1)
{
char buffer [256];
int rc = zmq_recv (receiver, buffer, 256, 0);
assert(rc != -1);
printf("message received: %s\n", buffer);
}
}


int main (void)
{
void *context = zmq_ctx_new ();
pthread_t thread1, thread2;
pthread_create (&thread1, NULL, server, context);
pthread_create (&thread2, NULL, client, context);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
zmq_ctx_destroy (context);
return 0;
}