diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-22 21:34:49 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-22 21:34:49 -0800 |
| commit | 29628309ae018c3f317eef9b03625d4ce3807a92 (patch) | |
| tree | 35f4df616b15f8e343a25b095c4ab76242275841 | |
| parent | 32cfbaccd7ac89c00207e5d1345d23abf455ce16 (diff) | |
| download | nng-29628309ae018c3f317eef9b03625d4ce3807a92.tar.gz nng-29628309ae018c3f317eef9b03625d4ce3807a92.tar.bz2 nng-29628309ae018c3f317eef9b03625d4ce3807a92.zip | |
Added lingering (1s default.)
| -rw-r--r-- | src/core/socket.c | 16 | ||||
| -rw-r--r-- | src/core/socket.h | 2 | ||||
| -rw-r--r-- | src/nng.h | 5 |
3 files changed, 15 insertions, 8 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index fb56a0bf..bbb9e48a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -26,7 +26,6 @@ nni_socket_recvq(nni_socket *s) return (s->s_urq); } - // nn_socket_create creates the underlying socket. int nni_socket_create(nni_socket **sockp, uint16_t proto) @@ -42,6 +41,7 @@ nni_socket_create(nni_socket **sockp, uint16_t proto) return (NNG_ENOMEM); } sock->s_ops = *ops; + sock->s_linger = NNG_DEFAULT_LINGER; if ((rv = nni_mutex_init(&sock->s_mx)) != 0) { nni_free(sock, sizeof (*sock)); @@ -55,7 +55,6 @@ nni_socket_create(nni_socket **sockp, uint16_t proto) NNI_LIST_INIT(&sock->s_pipes, nni_pipe, p_sock_node); NNI_LIST_INIT(&sock->s_eps, nni_endpt, ep_sock_node); - NNI_LIST_INIT(&sock->s_reap_eps, nni_endpt, ep_sock_node); if ((rv = sock->s_ops.proto_create(&sock->s_data, sock)) != 0) { nni_cond_fini(&sock->s_cv); @@ -88,8 +87,7 @@ nni_socket_close(nni_socket *sock) } nni_mutex_exit(&sock->s_mx); - // XXX: TODO: add socket linger timeout to this, from socket option. - linger = nni_clock(); + 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 @@ -131,10 +129,14 @@ nni_socket_close(nni_socket *sock) nni_cond_wait(&sock->s_cv); } - // We signaled the endpoints to shutdown and cleanup. We just - // need to wait for them to finish. + // We already told the endpoints to shutdown. We just + // need to reap them now. while ((ep = nni_list_first(&sock->s_eps)) != NULL) { - nni_cond_wait(&sock->s_cv); + nni_list_remove(&sock->s_eps, ep); + nni_mutex_exit(&sock->s_eps); + + nni_endpt_destroy(ep); + nni_mutex_enter(&sock->s_eps); } nni_mutex_exit(&sock->s_mx); diff --git a/src/core/socket.h b/src/core/socket.h index 5b321ae7..ff6a63d5 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -25,10 +25,10 @@ struct nng_socket { void * s_data; // Protocol private // XXX: options + nni_duration s_linger; nni_list_t s_eps; // active endpoints nni_list_t s_pipes; // pipes for this socket - nni_list_t s_reap_eps; // endpoint deathrow int s_closing; // Socket is closing int s_besteffort; // Best effort mode delivery @@ -346,6 +346,11 @@ NNG_DECL int nng_device(nng_socket *, nng_socket *); // This limit is built into other implementations, so do not change it. #define NNG_MAXADDRLEN (128) +// Default linger time in microseconds. The framework will wait up until +// this long for outgoing message queues to drain before closing underlying +// connections, when closing the socket itself. +#define NNG_LINGER_DEFAULT (1000000) + #ifdef __cplusplus } #endif |
