Commit f22b0b74 authored by Simon Giesecke's avatar Simon Giesecke

Problem: test_monitor failing for assertion on endpoint addresses on ZMQ_EVENT_LISTENING event

Solution: fix address passed and refactor set_local_address to remove code duplication and unnecessary address parsing when ZMQ_USE_FD is used
parent f3561f77
...@@ -101,22 +101,13 @@ zmq::tcp_listener_t::get_socket_name (zmq::fd_t fd_, ...@@ -101,22 +101,13 @@ zmq::tcp_listener_t::get_socket_name (zmq::fd_t fd_,
return zmq::get_socket_name<tcp_address_t> (fd_, socket_end_); return zmq::get_socket_name<tcp_address_t> (fd_, socket_end_);
} }
int zmq::tcp_listener_t::set_local_address (const char *addr_) int zmq::tcp_listener_t::create_socket (const char *addr_)
{ {
// Convert the textual address into address structure. // Convert the textual address into address structure.
int rc = _address.resolve (addr_, true, options.ipv6); int rc = _address.resolve (addr_, true, options.ipv6);
if (rc != 0) if (rc != 0)
return -1; return -1;
_address.to_string (_endpoint);
if (options.use_fd != -1) {
_s = options.use_fd;
_socket->event_listening (
make_unconnected_bind_endpoint_pair (_endpoint), _s);
return 0;
}
// Create a listening socket. // Create a listening socket.
_s = open_socket (_address.family (), SOCK_STREAM, IPPROTO_TCP); _s = open_socket (_address.family (), SOCK_STREAM, IPPROTO_TCP);
...@@ -200,8 +191,6 @@ int zmq::tcp_listener_t::set_local_address (const char *addr_) ...@@ -200,8 +191,6 @@ int zmq::tcp_listener_t::set_local_address (const char *addr_)
goto error; goto error;
#endif #endif
_socket->event_listening (make_unconnected_bind_endpoint_pair (_endpoint),
_s);
return 0; return 0;
error: error:
...@@ -211,6 +200,24 @@ error: ...@@ -211,6 +200,24 @@ error:
return -1; return -1;
} }
int zmq::tcp_listener_t::set_local_address (const char *addr_)
{
if (options.use_fd != -1) {
// in this case, the addr_ passed is not used and ignored, since the
// socket was already created by the application
_s = options.use_fd;
} else {
if (create_socket (addr_) == -1)
return -1;
}
_endpoint = get_socket_name (_s, socket_end_local);
_socket->event_listening (make_unconnected_bind_endpoint_pair (_endpoint),
_s);
return 0;
}
zmq::fd_t zmq::tcp_listener_t::accept () zmq::fd_t zmq::tcp_listener_t::accept ()
{ {
// The situation where connection cannot be accepted due to insufficient // The situation where connection cannot be accepted due to insufficient
......
...@@ -59,6 +59,8 @@ class tcp_listener_t : public stream_listener_base_t ...@@ -59,6 +59,8 @@ class tcp_listener_t : public stream_listener_base_t
// or was denied because of accept filters. // or was denied because of accept filters.
fd_t accept (); fd_t accept ();
int create_socket (const char *addr_);
// Address to listen on. // Address to listen on.
tcp_address_t _address; tcp_address_t _address;
......
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