mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-31 01:43:02 +08:00
Merge pull request #921 from mbarbisan/master
Allow TCP addresses to be re-resolved whenever there is a reconnection a...
This commit is contained in:
commit
49e035fb40
@ -240,7 +240,7 @@ int zmq::req_t::recv_reply_pipe (msg_t *msg_)
|
||||
|
||||
zmq::req_session_t::req_session_t (io_thread_t *io_thread_, bool connect_,
|
||||
socket_base_t *socket_, const options_t &options_,
|
||||
const address_t *addr_) :
|
||||
address_t *addr_) :
|
||||
session_base_t (io_thread_, connect_, socket_, options_, addr_),
|
||||
state (bottom)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ namespace zmq
|
||||
|
||||
req_session_t (zmq::io_thread_t *io_thread_, bool connect_,
|
||||
zmq::socket_base_t *socket_, const options_t &options_,
|
||||
const address_t *addr_);
|
||||
address_t *addr_);
|
||||
~req_session_t ();
|
||||
|
||||
// Overrides of the functions from session_base_t.
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
zmq::session_base_t *zmq::session_base_t::create (class io_thread_t *io_thread_,
|
||||
bool active_, class socket_base_t *socket_, const options_t &options_,
|
||||
const address_t *addr_)
|
||||
address_t *addr_)
|
||||
{
|
||||
|
||||
session_base_t *s = NULL;
|
||||
@ -67,7 +67,7 @@ zmq::session_base_t *zmq::session_base_t::create (class io_thread_t *io_thread_,
|
||||
|
||||
zmq::session_base_t::session_base_t (class io_thread_t *io_thread_,
|
||||
bool active_, class socket_base_t *socket_, const options_t &options_,
|
||||
const address_t *addr_) :
|
||||
address_t *addr_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
active (active_),
|
||||
|
@ -47,7 +47,7 @@ namespace zmq
|
||||
// Create a session of the particular type.
|
||||
static session_base_t *create (zmq::io_thread_t *io_thread_,
|
||||
bool active_, zmq::socket_base_t *socket_,
|
||||
const options_t &options_, const address_t *addr_);
|
||||
const options_t &options_, address_t *addr_);
|
||||
|
||||
// To be used once only, when creating the session.
|
||||
void attach_pipe (zmq::pipe_t *pipe_);
|
||||
@ -90,7 +90,7 @@ namespace zmq
|
||||
|
||||
session_base_t (zmq::io_thread_t *io_thread_, bool active_,
|
||||
zmq::socket_base_t *socket_, const options_t &options_,
|
||||
const address_t *addr_);
|
||||
address_t *addr_);
|
||||
virtual ~session_base_t ();
|
||||
|
||||
private:
|
||||
@ -152,7 +152,7 @@ namespace zmq
|
||||
bool has_linger_timer;
|
||||
|
||||
// Protocol and address to use when connecting.
|
||||
const address_t *addr;
|
||||
address_t *addr;
|
||||
|
||||
session_base_t (const session_base_t&);
|
||||
const session_base_t &operator = (const session_base_t&);
|
||||
|
@ -585,14 +585,8 @@ int zmq::socket_base_t::connect (const char *addr_)
|
||||
|
||||
// Resolve address (if needed by the protocol)
|
||||
if (protocol == "tcp") {
|
||||
paddr->resolved.tcp_addr = new (std::nothrow) tcp_address_t ();
|
||||
alloc_assert (paddr->resolved.tcp_addr);
|
||||
int rc = paddr->resolved.tcp_addr->resolve (
|
||||
address.c_str (), false, options.ipv6);
|
||||
if (rc != 0) {
|
||||
delete paddr;
|
||||
return -1;
|
||||
}
|
||||
// Defer resolution until a socket is opened
|
||||
paddr->resolved.tcp_addr = NULL;
|
||||
}
|
||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||
else
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_,
|
||||
class session_base_t *session_, const options_t &options_,
|
||||
const address_t *addr_, bool delayed_start_) :
|
||||
address_t *addr_, bool delayed_start_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
addr (addr_),
|
||||
@ -209,6 +209,24 @@ int zmq::tcp_connecter_t::open ()
|
||||
{
|
||||
zmq_assert (s == retired_fd);
|
||||
|
||||
// Resolve the address
|
||||
if (addr->resolved.tcp_addr != NULL) {
|
||||
delete addr->resolved.tcp_addr;
|
||||
addr->resolved.tcp_addr = NULL;
|
||||
}
|
||||
zmq_assert (addr->resolved.tcp_addr == NULL);
|
||||
|
||||
addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t ();
|
||||
alloc_assert (addr->resolved.tcp_addr);
|
||||
int rc = addr->resolved.tcp_addr->resolve (
|
||||
addr->address.c_str (), false, options.ipv6);
|
||||
if (rc != 0) {
|
||||
delete addr->resolved.tcp_addr;
|
||||
addr->resolved.tcp_addr = NULL;
|
||||
return -1;
|
||||
}
|
||||
zmq_assert (addr->resolved.tcp_addr != NULL);
|
||||
|
||||
// Create the socket.
|
||||
s = open_socket (addr->resolved.tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP);
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
@ -244,7 +262,7 @@ int zmq::tcp_connecter_t::open ()
|
||||
set_ip_type_of_service (s, options.tos);
|
||||
|
||||
// Connect to the remote peer.
|
||||
int rc = ::connect (
|
||||
rc = ::connect (
|
||||
s, addr->resolved.tcp_addr->addr (),
|
||||
addr->resolved.tcp_addr->addrlen ());
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace zmq
|
||||
// then starts connection process.
|
||||
tcp_connecter_t (zmq::io_thread_t *io_thread_,
|
||||
zmq::session_base_t *session_, const options_t &options_,
|
||||
const address_t *addr_, bool delayed_start_);
|
||||
address_t *addr_, bool delayed_start_);
|
||||
~tcp_connecter_t ();
|
||||
|
||||
private:
|
||||
@ -82,7 +82,7 @@ namespace zmq
|
||||
fd_t connect ();
|
||||
|
||||
// Address to connect to. Owned by session_base_t.
|
||||
const address_t *addr;
|
||||
address_t *addr;
|
||||
|
||||
// Underlying socket.
|
||||
fd_t s;
|
||||
|
@ -31,13 +31,13 @@ int main (void)
|
||||
int rc = zmq_connect (sock, "tcp://localhost:1234");
|
||||
assert (rc == 0);
|
||||
|
||||
// Because of lazy resolution of TCP names, this will succeed
|
||||
rc = zmq_connect (sock, "tcp://localhost:invalid");
|
||||
assert (rc == -1);
|
||||
assert (errno == EINVAL);
|
||||
assert (rc == 0);
|
||||
|
||||
// Because of lazy resolution of TCP names, this will succeed
|
||||
rc = zmq_connect (sock, "tcp://in val id:1234");
|
||||
assert (rc == -1);
|
||||
assert (errno == EINVAL);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_connect (sock, "invalid://localhost:1234");
|
||||
assert (rc == -1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user