Created
July 21, 2014 18:56
-
-
Save gsalgado/3f2c9bb931840351266d to your computer and use it in GitHub Desktop.
zmq_close(socket) doesn't seem to release inproc endpoint immediately
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
#include <zmq.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <assert.h> | |
// The second bind will eventually fail with an 'Address already in use' | |
// unless we sleep long enough. I'd expect the zmq_close(sock) call to release | |
// the endpoint imeediately but that doesn't seem to be the case. | |
int main (void) | |
{ | |
// Socket to talk to clients | |
void *context = zmq_ctx_new (); | |
void *sock = zmq_socket (context, ZMQ_PUSH); | |
int rc = zmq_bind (sock, "inproc://in"); | |
assert (rc == 0); | |
int i = 0; | |
while (1) { | |
printf("Iteration: %d\n", i); | |
zmq_close (sock); | |
sleep(0.1); | |
sock = zmq_socket (context, ZMQ_PUSH); | |
rc = zmq_bind (sock, "inproc://in"); | |
if (rc != 0) { | |
printf ("bind failed: %s\n", strerror (errno)); | |
return -1; | |
} | |
i += 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment