Commit c84ca01e authored by Martin Hurton's avatar Martin Hurton

Be more conservative about when to generate ZMQ_EVENT_CLOSE_FAILED

This also fixes a bug in tcp_connecter and tcp_listener, which
generated the event not when they failed to close the socket but
when the succeed to close it.
parent 6ac5cf86
...@@ -224,10 +224,7 @@ int zmq::ipc_connecter_t::close () ...@@ -224,10 +224,7 @@ int zmq::ipc_connecter_t::close ()
{ {
zmq_assert (s != retired_fd); zmq_assert (s != retired_fd);
int rc = ::close (s); int rc = ::close (s);
if (rc != 0) { errno_assert (rc == 0);
session->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
return -1;
}
session->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s); session->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s);
s = retired_fd; s = retired_fd;
return 0; return 0;
......
...@@ -169,10 +169,7 @@ int zmq::ipc_listener_t::close () ...@@ -169,10 +169,7 @@ int zmq::ipc_listener_t::close ()
{ {
zmq_assert (s != retired_fd); zmq_assert (s != retired_fd);
int rc = ::close (s); int rc = ::close (s);
if (rc != 0) { errno_assert (rc == 0);
socket->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
return -1;
}
// If there's an underlying UNIX domain socket, get rid of the file it // If there's an underlying UNIX domain socket, get rid of the file it
// is associated with. // is associated with.
......
...@@ -298,13 +298,9 @@ void zmq::tcp_connecter_t::close () ...@@ -298,13 +298,9 @@ void zmq::tcp_connecter_t::close ()
zmq_assert (s != retired_fd); zmq_assert (s != retired_fd);
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
int rc = closesocket (s); int rc = closesocket (s);
if (unlikely (rc != SOCKET_ERROR))
session->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
#else #else
int rc = ::close (s); int rc = ::close (s);
if (unlikely (rc == 0))
session->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
errno_assert (rc == 0); errno_assert (rc == 0);
#endif #endif
session->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s); session->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s);
......
...@@ -116,13 +116,9 @@ void zmq::tcp_listener_t::close () ...@@ -116,13 +116,9 @@ void zmq::tcp_listener_t::close ()
zmq_assert (s != retired_fd); zmq_assert (s != retired_fd);
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
int rc = closesocket (s); int rc = closesocket (s);
if (unlikely (rc != SOCKET_ERROR))
socket->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
#else #else
int rc = ::close (s); int rc = ::close (s);
if (unlikely (rc == 0))
socket->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
errno_assert (rc == 0); errno_assert (rc == 0);
#endif #endif
socket->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s); socket->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment