Skip to content

Commit

Permalink
AF_UNIX support may fail on bind
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Sep 8, 2022
1 parent b2921d7 commit b77543a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
int rc = 0;
int saved_errno = 0;

// It appears that a lack of runtime AF_UNIX support
// can fail in more than one way.
// At least: open_socket can fail or later in bind
bool ipc_fallback_on_tcpip = true;

// Create a listening socket.
const SOCKET listener = open_socket (AF_UNIX, SOCK_STREAM, 0);
if (listener == retired_fd) {
Expand All @@ -596,9 +601,11 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
rc = bind (listener, const_cast<sockaddr *> (address.addr ()),
address.addrlen ());
if (rc != 0) {
errno = wsa_error_to_errno (WSAGetLastError ());
goto error_closelistener;
}
// if we got here, ipc should be working,
// so raise any remaining errors
ipc_fallback_on_tcpip = false;

// Listen for incoming connections.
rc = listen (listener, 1);
Expand Down Expand Up @@ -665,8 +672,12 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
filename.clear ();
}

errno = saved_errno;
// ipc failed due to lack of AF_UNIX support, fallback on tcpip
if (ipc_fallback_on_tcpip) {
goto try_tcpip;
}

errno = saved_errno;
return -1;

try_tcpip:
Expand Down

0 comments on commit b77543a

Please sign in to comment.