aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-16 13:41:29 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-16 13:41:29 -0700
commit4a0481a0c3dc8e3509a29c58da0de6db0623f86f (patch)
treef0f456c9849141817745a7050b4e94dc68ff265f
parent396d8a243df89680b850626193e0b23567b02585 (diff)
downloadnng-4a0481a0c3dc8e3509a29c58da0de6db0623f86f.tar.gz
nng-4a0481a0c3dc8e3509a29c58da0de6db0623f86f.tar.bz2
nng-4a0481a0c3dc8e3509a29c58da0de6db0623f86f.zip
Fix EAGAIN (timeout thread can run before we finish scheduling!)
-rw-r--r--src/core/msgqueue.c14
-rw-r--r--src/nng.c14
2 files changed, 14 insertions, 14 deletions
diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c
index 71c6dff4..d98c68be 100644
--- a/src/core/msgqueue.c
+++ b/src/core/msgqueue.c
@@ -358,13 +358,6 @@ nni_msgq_aio_put(nni_msgq *mq, nni_aio *aio)
nni_aio_list_append(&mq->mq_aio_putq, aio);
nni_msgq_run_putq(mq);
-
- // if this was a non-blocking operation, and we couldn't finish
- // it synchronously in the above run_putq, then abort.
- if ((aio->a_expire == NNI_TIME_ZERO) && (nni_aio_list_active(aio))) {
- nni_aio_list_remove(aio);
- nni_aio_finish(aio, NNG_EAGAIN, 0);
- }
nni_msgq_run_notify(mq);
nni_mtx_unlock(&mq->mq_lock);
@@ -391,13 +384,6 @@ nni_msgq_aio_get(nni_msgq *mq, nni_aio *aio)
nni_aio_list_append(&mq->mq_aio_getq, aio);
nni_msgq_run_getq(mq);
-
- // if this was a non-blocking operation, and we couldn't finish
- // it synchronously in the above run_getq, then abort.
- if ((aio->a_expire == NNI_TIME_ZERO) && (nni_aio_list_active(aio))) {
- nni_aio_list_remove(aio);
- nni_aio_finish(aio, NNG_EAGAIN, 0);
- }
nni_msgq_run_notify(mq);
nni_mtx_unlock(&mq->mq_lock);
diff --git a/src/nng.c b/src/nng.c
index 98442a83..54df9980 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -160,6 +160,13 @@ nng_recvmsg(nng_socket sid, nng_msg **msgp, int flags)
rv = nni_sock_recvmsg(sock, msgp, expire);
nni_sock_rele(sock);
+
+ // Possibly massage nonblocking attempt. Note that nonblocking is
+ // still done asynchronously, and the calling thread loses context.
+ if ((rv == NNG_ETIMEDOUT) && (expire == NNI_TIME_ZERO)) {
+ rv = NNG_EAGAIN;
+ }
+
return (rv);
}
@@ -214,6 +221,13 @@ nng_sendmsg(nng_socket sid, nng_msg *msg, int flags)
rv = nni_sock_sendmsg(sock, msg, expire);
nni_sock_rele(sock);
+
+ // Possibly massage nonblocking attempt. Note that nonblocking is
+ // still done asynchronously, and the calling thread loses context.
+ if ((rv == NNG_ETIMEDOUT) && (expire == NNI_TIME_ZERO)) {
+ rv = NNG_EAGAIN;
+ }
+
return (rv);
}