aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-04 18:30:33 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-04 18:30:33 -0800
commit40da92f0fffc7b69f876ca060d9b4e6682e45a8c (patch)
tree3147f840adc3815dd55693e440380992f76b1ba9 /src/transport
parentc1d11425846baf22e9a07b0f2bf2ad405e0b42e5 (diff)
downloadnng-40da92f0fffc7b69f876ca060d9b4e6682e45a8c.tar.gz
nng-40da92f0fffc7b69f876ca060d9b4e6682e45a8c.tar.bz2
nng-40da92f0fffc7b69f876ca060d9b4e6682e45a8c.zip
Fix close related races (POSIX close is a PITA).
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/tcp/tcp.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 00d9a2f3..249c2329 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -55,7 +55,7 @@ nni_tcp_pipe_close(void *arg)
{
nni_tcp_pipe *pipe = arg;
- nni_plat_tcp_close(&pipe->fd);
+ nni_plat_tcp_shutdown(&pipe->fd);
}
@@ -64,6 +64,7 @@ nni_tcp_pipe_destroy(void *arg)
{
nni_tcp_pipe *pipe = arg;
+ nni_plat_tcp_fini(&pipe->fd);
NNI_FREE_STRUCT(pipe);
}
@@ -176,6 +177,7 @@ nni_tcp_ep_init(void **epp, const char *url, uint16_t proto)
ep->closed = 0;
ep->proto = proto;
ep->ipv4only = 0;
+ nni_plat_tcp_init(&ep->fd);
(void) snprintf(ep->addr, sizeof (ep->addr), "%s", url);
@@ -189,6 +191,7 @@ nni_tcp_ep_fini(void *arg)
{
nni_tcp_ep *ep = arg;
+ nni_plat_tcp_fini(&ep->fd);
NNI_FREE_STRUCT(ep);
}
@@ -198,7 +201,7 @@ nni_tcp_ep_close(void *arg)
{
nni_tcp_ep *ep = arg;
- nni_plat_tcp_close(&ep->fd);
+ nni_plat_tcp_shutdown(&ep->fd);
}
@@ -340,6 +343,7 @@ nni_tcp_ep_connect(void *arg, void **pipep)
if ((pipe = NNI_ALLOC_STRUCT(pipe)) == NULL) {
return (NNG_ENOMEM);
}
+ nni_plat_tcp_init(&pipe->fd);
pipe->proto = ep->proto;
// Port is in the same place for both v4 and v6.
@@ -353,7 +357,8 @@ nni_tcp_ep_connect(void *arg, void **pipep)
}
if ((rv = nni_tcp_negotiate(pipe)) != 0) {
- nni_plat_tcp_close(&pipe->fd);
+ nni_plat_tcp_shutdown(&pipe->fd);
+ nni_plat_tcp_fini(&pipe->fd);
NNI_FREE_STRUCT(pipe);
return (rv);
}
@@ -405,13 +410,15 @@ nni_tcp_ep_accept(void *arg, void **pipep)
return (NNG_ENOMEM);
}
pipe->proto = ep->proto;
+ nni_plat_tcp_init(&pipe->fd);
if ((rv = nni_plat_tcp_accept(&pipe->fd, &ep->fd)) != 0) {
NNI_FREE_STRUCT(pipe);
return (rv);
}
if ((rv = nni_tcp_negotiate(pipe)) != 0) {
- nni_plat_tcp_close(&pipe->fd);
+ nni_plat_tcp_shutdown(&pipe->fd);
+ nni_plat_tcp_fini(&pipe->fd);
NNI_FREE_STRUCT(pipe);
return (rv);
}