Allow to set up a source address and port for outgoing tcp connections in zmq_connect()

Few examples:
tcp:://192.168.0.4:55555;192.168.0.254:1234
tcp:://192.168.0.4:0;192.168.0.254:1234
tcp:://eth2:55555;192.168.0.254:1234
This commit is contained in:
nikita kozlov
2014-04-30 14:43:37 +02:00
parent 4307641f27
commit acb6807041
6 changed files with 174 additions and 27 deletions

View File

@@ -261,6 +261,15 @@ int zmq::tcp_connecter_t::open ()
if (options.tos != 0)
set_ip_type_of_service (s, options.tos);
// Set a source address for conversations
if (addr->resolved.tcp_addr->has_src_addr ()) {
rc = ::bind (s, addr->resolved.tcp_addr->src_addr (), addr->resolved.tcp_addr->src_addrlen ());
if (rc == -1) {
return -1;
}
}
// Connect to the remote peer.
rc = ::connect (
s, addr->resolved.tcp_addr->addr (),