Merge pull request #377 from hurtonm/master

{tcp|ipc}_listener: close socket when set_address () fails
This commit is contained in:
Pieter Hintjens 2012-06-13 06:09:42 -07:00
commit f35bed0edc
2 changed files with 18 additions and 6 deletions

View File

@ -145,7 +145,7 @@ int zmq::ipc_listener_t::set_address (const char *addr_)
// Bind the socket to the file path.
rc = bind (s, address.addr (), address.addrlen ());
if (rc != 0)
return -1;
goto error;
filename.assign(addr_);
has_file = true;
@ -153,10 +153,16 @@ int zmq::ipc_listener_t::set_address (const char *addr_)
// Listen for incomming connections.
rc = listen (s, options.backlog);
if (rc != 0)
return -1;
goto error;
socket->monitor_event (ZMQ_EVENT_LISTENING, addr_, s);
return 0;
error:
int err = errno;
close ();
errno = err;
return -1;
}
int zmq::ipc_listener_t::close ()

View File

@ -208,11 +208,11 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
#ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) {
errno = wsa_error_to_errno (WSAGetLastError ());
return -1;
goto error;
}
#else
if (rc != 0)
return -1;
goto error;
#endif
// Listen for incomming connections.
@ -220,15 +220,21 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
#ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) {
errno = wsa_error_to_errno (WSAGetLastError ());
return -1;
goto error;
}
#else
if (rc != 0)
return -1;
goto error;
#endif
socket->monitor_event (ZMQ_EVENT_LISTENING, addr_, s);
return 0;
error:
int err = errno;
close ();
errno = err;
return -1;
}
zmq::fd_t zmq::tcp_listener_t::accept ()