aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/endpt.c23
-rw-r--r--src/core/endpt.h1
-rw-r--r--src/core/socket.c27
-rw-r--r--src/core/socket.h1
4 files changed, 19 insertions, 33 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c
index 362af82c..92a974a8 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -166,6 +166,13 @@ nni_ep_close(nni_ep *ep)
nni_mtx *mx = &ep->ep_sock->s_mx;
nni_mtx_lock(nni_idlock);
+ if (ep->ep_id != 0) {
+ // We might have removed this already as a result of
+ // application initiated endpoint close request instead
+ // of socket close.
+ nni_idhash_remove(nni_endpoints, ep->ep_id);
+ ep->ep_id = 0;
+ }
while (ep->ep_refcnt) {
nni_cv_wait(&ep->ep_refcv);
}
@@ -186,15 +193,6 @@ nni_ep_close(nni_ep *ep)
nni_thr_fini(&ep->ep_thr);
ep->ep_ops.ep_fini(ep->ep_data);
- nni_mtx_lock(nni_idlock);
- if (ep->ep_id != 0) {
- // We might have removed this already as a result of
- // application initiated endpoint close request instead
- // of socket close.
- nni_idhash_remove(nni_endpoints, ep->ep_id);
- }
- nni_mtx_unlock(nni_idlock);
-
nni_cv_fini(&ep->ep_cv);
NNI_FREE_STRUCT(ep);
}
@@ -498,3 +496,10 @@ nni_ep_listen(nni_ep *ep, int flags)
return (0);
}
+
+
+void
+nni_ep_list_init(nni_list *list)
+{
+ NNI_LIST_INIT(list, nni_ep, ep_node);
+}
diff --git a/src/core/endpt.h b/src/core/endpt.h
index 3a30f73e..2b685590 100644
--- a/src/core/endpt.h
+++ b/src/core/endpt.h
@@ -49,5 +49,6 @@ extern int nni_ep_accept(nni_ep *, nni_pipe **);
extern void nni_ep_close(nni_ep *);
extern int nni_ep_dial(nni_ep *, int);
extern int nni_ep_listen(nni_ep *, int);
+extern void nni_ep_list_init(nni_list *);
#endif // CORE_ENDPT_H
diff --git a/src/core/socket.c b/src/core/socket.c
index 76843174..b285de85 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -94,7 +94,9 @@ nni_sock_hold_close(nni_sock **sockp, uint32_t id)
sock->s_id = 0;
sock->s_closed = 1;
nni_mtx_unlock(nni_idlock);
+
nni_sock_shutdown(sock);
+
nni_mtx_lock(nni_idlock);
while (sock->s_refcnt != 0) {
nni_cv_wait(&sock->s_refcv);
@@ -106,28 +108,6 @@ nni_sock_hold_close(nni_sock **sockp, uint32_t id)
}
-// nni_sock_held_close uses an existing hold on the socket, but is
-// otherwise pretty much the same as nni_sock_hold_close. When this
-// returns there will be no other user-land references to the socket.
-void
-nni_sock_held_close(nni_sock *sock)
-{
- nni_mtx_lock(nni_idlock);
- sock->s_closed = 1;
- if (sock->s_id != 0) {
- nni_idhash_remove(nni_sockets, sock->s_id);
- sock->s_id = 0;
- }
- nni_mtx_unlock(nni_idlock);
- nni_sock_shutdown(sock);
- nni_mtx_lock(nni_idlock);
- while (sock->s_refcnt != 0) {
- nni_cv_wait(&sock->s_refcv);
- }
- nni_mtx_unlock(nni_idlock);
-}
-
-
int
nni_sock_pipe_add(nni_sock *sock, nni_pipe *pipe)
{
@@ -419,7 +399,8 @@ nni_sock_open(nni_sock **sockp, uint16_t pnum)
nni_pipe_sock_list_init(&sock->s_pipes);
nni_pipe_sock_list_init(&sock->s_idles);
- NNI_LIST_INIT(&sock->s_eps, nni_ep, ep_node);
+ nni_ep_list_init(&sock->s_eps);
+
sock->s_send_fd.sn_init = 0;
sock->s_recv_fd.sn_init = 0;
diff --git a/src/core/socket.h b/src/core/socket.h
index 21449dc9..dc6f5530 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -65,7 +65,6 @@ struct nni_socket {
extern int nni_sock_hold(nni_sock **, uint32_t);
extern int nni_sock_hold_close(nni_sock **, uint32_t);
-extern void nni_sock_held_close(nni_sock *);
extern void nni_sock_rele(nni_sock *);
extern int nni_sock_open(nni_sock **, uint16_t);
extern void nni_sock_close(nni_sock *);