diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-06-30 08:37:08 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-06-30 08:37:08 -0700 |
| commit | 69c309ec479900f9389aacba18d8c1d3026ece46 (patch) | |
| tree | 588da73835c0e241dbf0f2f0d7ee649271e815fe /src | |
| parent | c4c4e96a56863bfd365df18495d5cf6ab35cc880 (diff) | |
| download | nng-69c309ec479900f9389aacba18d8c1d3026ece46.tar.gz nng-69c309ec479900f9389aacba18d8c1d3026ece46.tar.bz2 nng-69c309ec479900f9389aacba18d8c1d3026ece46.zip | |
IPC fixes: correct handling of path removal, and path absence.
Diffstat (limited to 'src')
| -rw-r--r-- | src/platform/posix/posix_socket.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/platform/posix/posix_socket.c b/src/platform/posix/posix_socket.c index 9dd3a274..ce887a78 100644 --- a/src/platform/posix/posix_socket.c +++ b/src/platform/posix/posix_socket.c @@ -280,22 +280,26 @@ nni_posix_sock_listen(nni_posix_sock *s, const nni_sockaddr *saddr) } } (void) close(chkfd); - - // Record the path so we unlink it later - s->unlink = nni_alloc(strlen(saddr->s_un.s_path.sa_path) + 1); - if (s->unlink == NULL) { - (void) close(fd); - return (NNG_ENOMEM); - } } - if (bind(fd, (struct sockaddr *) &ss, len) < 0) { rv = nni_plat_errno(errno); (void) close(fd); return (rv); } + // For IPC, record the path so we unlink it later + if ((saddr->s_un.s_family == NNG_AF_IPC) && + (saddr->s_un.s_path.sa_path[0] != 0)) { + s->unlink = nni_alloc(strlen(saddr->s_un.s_path.sa_path) + 1); + if (s->unlink == NULL) { + (void) close(fd); + (void) unlink(saddr->s_un.s_path.sa_path); + return (NNG_ENOMEM); + } + strcpy(s->unlink, saddr->s_un.s_path.sa_path); + } + // Listen -- 128 depth is probably sufficient. If it isn't, other // bad things are going to happen. if (listen(fd, 128) != 0) { @@ -485,6 +489,12 @@ nni_posix_sock_connect_sync(nni_posix_sock *s, const nni_sockaddr *addr, if (connect(fd, (struct sockaddr *) &ss, len) != 0) { rv = nni_plat_errno(errno); + // Unix domain sockets return ENOENT when nothing is there. + // Massage this into ECONNREFUSED, to provide more consistent + // behavior. + if (rv == NNG_ENOENT) { + rv = NNG_ECONNREFUSED; + } (void) close(fd); return (rv); } |
