Created
May 24, 2013 05:29
-
-
Save op/5641440 to your computer and use it in GitHub Desktop.
If there is no timeout defined on a socket, and the socket is closed while another thread is waiting in nn_recv(), it would be very helpful for me to get an error back directly. Similar to how nn_term() works.
This file contains hidden or 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 "src/nn.h" | |
#include "src/reqrep.h" | |
#include "src/utils/err.c" | |
#include "src/utils/thread.c" | |
#include "src/utils/sleep.c" | |
#include <stddef.h> | |
#include <assert.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int rep; | |
void worker (void *arg) | |
{ | |
int rc; | |
int i; | |
int timeo; | |
char buf[3]; | |
rc = nn_recv(rep, buf, 3, 0); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
int rc; | |
int req; | |
int timeo; | |
struct nn_thread thread; | |
req = nn_socket(AF_SP, NN_REQ); | |
assert(req != -1); | |
rc = nn_connect(req, "inproc://thread_recv_close"); | |
assert(rc >= 0); | |
rep = nn_socket(AF_SP, NN_REP); | |
assert(rep != -1); | |
rc = nn_bind(rep, "inproc://thread_recv_close"); | |
assert(rc >= 0); | |
/* Wait a bit till the worker thread blocks in nn_recv(). */ | |
nn_thread_init(&thread, worker, NULL); | |
nn_sleep(100); | |
/* Calling nn_term() before close will unblock the thread. */ | |
/* nn_term(); */ | |
rc = nn_close(req); | |
assert(rc == 0); | |
rc = nn_close(rep); | |
assert(rc == 0); | |
nn_thread_term(&thread); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment