mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 18:55:10 +01:00
Merge pull request #377 from hurtonm/master
{tcp|ipc}_listener: close socket when set_address () fails
This commit is contained in:
commit
f35bed0edc
@ -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 ()
|
||||
|
@ -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 ()
|
||||
|
Loading…
Reference in New Issue
Block a user