aboutsummaryrefslogtreecommitdiff
path: root/src/nng.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2021-12-27 23:10:29 -0800
committerGarrett D'Amore <garrett@damore.org>2021-12-27 23:10:29 -0800
commit2fbfd7e5c3ad245de2c905720eb8d9d5b27b6739 (patch)
tree2907ec3f298b2b38827060623d3f6e2577dda011 /src/nng.c
parent7b02ddc2d7077439992a10bb69553f89b5ee5903 (diff)
downloadnng-2fbfd7e5c3ad245de2c905720eb8d9d5b27b6739.tar.gz
nng-2fbfd7e5c3ad245de2c905720eb8d9d5b27b6739.tar.bz2
nng-2fbfd7e5c3ad245de2c905720eb8d9d5b27b6739.zip
Introduce nng_device_aio().
This function is like nng_device(), but runs asynchronously. Also, this fixes #1503 nng_device causes nng_close to blocking
Diffstat (limited to 'src/nng.c')
-rw-r--r--src/nng.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/nng.c b/src/nng.c
index bc46fea5..c48ccd0b 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -1158,8 +1158,8 @@ nng_pipe_notify(nng_socket s, nng_pipe_ev ev, nng_pipe_cb cb, void *arg)
return (0);
}
-int
-nng_device(nng_socket s1, nng_socket s2)
+void
+nng_device_aio(nng_aio *aio, nng_socket s1, nng_socket s2)
{
int rv;
nni_sock *sock1 = NULL;
@@ -1167,23 +1167,44 @@ nng_device(nng_socket s1, nng_socket s2)
if ((s1.id > 0) && (s1.id != (uint32_t) -1)) {
if ((rv = nni_sock_find(&sock1, s1.id)) != 0) {
- return (rv);
+ if (nni_aio_begin(aio) == 0) {
+ nni_aio_finish_error(aio, rv);
+ }
+ return;
}
}
if (((s2.id > 0) && (s2.id != (uint32_t) -1)) && (s2.id != s1.id)) {
if ((rv = nni_sock_find(&sock2, s2.id)) != 0) {
nni_sock_rele(sock1);
- return (rv);
+ if (nni_aio_begin(aio) == 0) {
+ nni_aio_finish_error(aio, rv);
+ }
+ return;
}
}
- rv = nni_device(sock1, sock2);
+ nni_device(aio, sock1, sock2);
if (sock1 != NULL) {
nni_sock_rele(sock1);
}
if (sock2 != NULL) {
nni_sock_rele(sock2);
}
+}
+
+int
+nng_device(nng_socket s1, nng_socket s2)
+{
+ nni_aio aio;
+ int rv;
+ if ((rv = nni_init()) != 0) {
+ return (rv);
+ }
+ nni_aio_init(&aio, NULL, NULL);
+ nng_device_aio(&aio, s1, s2);
+ nni_aio_wait(&aio);
+ rv = nni_aio_result(&aio);
+ nni_aio_fini(&aio);
return (rv);
}