diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-23 02:04:58 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-23 02:04:58 -0800 |
| commit | 471a454900ab6142e5a3c1f53866996172d2aad4 (patch) | |
| tree | 8238d500faeefce1d970f6f62e648bae9d66736e /src | |
| parent | d708b178f049839bfdbaf0289e400363eac78a30 (diff) | |
| download | nng-471a454900ab6142e5a3c1f53866996172d2aad4.tar.gz nng-471a454900ab6142e5a3c1f53866996172d2aad4.tar.bz2 nng-471a454900ab6142e5a3c1f53866996172d2aad4.zip | |
Don't linger if there are no possible readers present.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/msgqueue.c | 2 | ||||
| -rw-r--r-- | src/core/socket.c | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c index 823f6e45..fd89b7ad 100644 --- a/src/core/msgqueue.c +++ b/src/core/msgqueue.c @@ -42,7 +42,7 @@ nni_msgqueue_create(nni_msgqueue **mqp, int cap) // We allocate 2 extra cells in the fifo. One to accommodate a // waiting writer when cap == 0. (We can "briefly" move the message - // through. This lets us behave the same as unbuffered Go channels. + // through.) This lets us behave the same as unbuffered Go channels. // The second cell is to permit pushback later, e.g. for REQ to stash // a message back at the end to do a retry. alloc = cap + 2; diff --git a/src/core/socket.c b/src/core/socket.c index e3298886..dee1561d 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -59,7 +59,7 @@ nni_socket_create(nni_socket **sockp, uint16_t proto) if (((rv = nni_msgqueue_create(&sock->s_uwq, 0)) != 0) || ((rv = nni_msgqueue_create(&sock->s_urq, 0)) != 0)) { - goto fail; + goto fail; } if ((rv = sock->s_ops.proto_create(&sock->s_data, sock)) != 0) { @@ -67,6 +67,7 @@ nni_socket_create(nni_socket **sockp, uint16_t proto) } *sockp = sock; return (0); + fail: if (sock->s_urq != NULL) { nni_msgqueue_destroy(sock->s_urq); @@ -98,9 +99,17 @@ nni_socket_close(nni_socket *sock) NNI_LIST_FOREACH (&sock->s_eps, ep) { nni_endpt_close(ep); } + + // Special optimization; if there are no pipes connected, + // then there is no reason to linger since there's nothing that + // could possibly send this data out. + if (nni_list_first(&sock->s_pipes) == NULL) { + linger = NNI_TIME_ZERO; + } else { + linger = nni_clock() + sock->s_linger; + } nni_mutex_exit(&sock->s_mx); - linger = nni_clock() + sock->s_linger; // We drain the upper write queue. This is just like closing it, // except that the protocol gets a chance to get the messages and |
