diff --git a/src/options.cpp b/src/options.cpp index c717c253..74f9593e 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -501,14 +501,6 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) } break; - case ZMQ_LAST_ENDPOINT: - if (*optvallen_ >= last_endpoint.size () + 1) { - memcpy (optval_, last_endpoint.c_str (), last_endpoint.size () + 1); - *optvallen_ = last_endpoint.size () + 1; - return 0; - } - break; - case ZMQ_MECHANISM: if (is_int) { *value = mechanism; diff --git a/src/options.hpp b/src/options.hpp index 1b706b71..3a14b418 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -50,9 +50,6 @@ namespace zmq unsigned char identity_size; unsigned char identity [256]; - // Last socket endpoint resolved URI - std::string last_endpoint; - // Maximum tranfer rate [kb/s]. Default 100kb/s. int rate; diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 6e4853e0..25c4bbff 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -302,6 +302,16 @@ int zmq::socket_base_t::getsockopt (int option_, void *optval_, return 0; } + if (option_ == ZMQ_LAST_ENDPOINT) { + if (*optvallen_ < last_endpoint.size () + 1) { + errno = EINVAL; + return -1; + } + strcpy (static_cast (optval_), last_endpoint.c_str ()); + *optvallen_ = last_endpoint.size () + 1; + return 0; + } + return options.getsockopt (option_, optval_, optvallen_); } @@ -333,7 +343,7 @@ int zmq::socket_base_t::bind (const char *addr_) int rc = register_endpoint (addr_, endpoint); if (rc == 0) { // Save last endpoint URI - options.last_endpoint.assign (addr_); + last_endpoint.assign (addr_); } return rc; } @@ -364,7 +374,7 @@ int zmq::socket_base_t::bind (const char *addr_) } // Save last endpoint URI - listener->get_address (options.last_endpoint); + listener->get_address (last_endpoint); add_endpoint (addr_, (own_t *) listener); return 0; @@ -383,7 +393,7 @@ int zmq::socket_base_t::bind (const char *addr_) } // Save last endpoint URI - listener->get_address (options.last_endpoint); + listener->get_address (last_endpoint); add_endpoint (addr_, (own_t *) listener); return 0; @@ -478,7 +488,7 @@ int zmq::socket_base_t::connect (const char *addr_) send_bind (peer.socket, new_pipes [1], false); // Save last endpoint URI - options.last_endpoint.assign (addr_); + last_endpoint.assign (addr_); // remember inproc connections for disconnect inprocs.insert (inprocs_t::value_type (std::string (addr_), new_pipes[0])); @@ -556,7 +566,7 @@ int zmq::socket_base_t::connect (const char *addr_) } // Save last endpoint URI - paddr->to_string (options.last_endpoint); + paddr->to_string (last_endpoint); add_endpoint (addr_, (own_t *) session); return 0; diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 603ab7a8..61bfbc15 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -238,6 +238,9 @@ namespace zmq // Bitmask of events being monitored int monitor_events; + // Last socket endpoint resolved URI + std::string last_endpoint; + socket_base_t (const socket_base_t&); const socket_base_t &operator = (const socket_base_t&); mutex_t sync;