diff options
author | Brennan Ashton <bashton@brennanashton.com> | 2018-11-02 23:50:49 -0700 |
---|---|---|
committer | Andrej Rode <mail@andrejro.de> | 2018-11-28 00:02:35 +0100 |
commit | b76a95c52f812181605248f1f590a199e2e5d0e3 (patch) | |
tree | 9493ca923d95928a4a662e2c05f6d1c95b426029 | |
parent | 0733bc4f788c424264d26c1a1f82d831c91b2c15 (diff) |
gr-zeromq: Add last_endpoint function to zmq source and sink blocks
The main reason for this is is allows you to read back the real
address string in the case that port 0 is used and the OS has
auto-assigned a free port.
26 files changed, 118 insertions, 0 deletions
diff --git a/gr-zeromq/include/gnuradio/zeromq/pub_msg_sink.h b/gr-zeromq/include/gnuradio/zeromq/pub_msg_sink.h index fb046ca84b..cb79dacc01 100644 --- a/gr-zeromq/include/gnuradio/zeromq/pub_msg_sink.h +++ b/gr-zeromq/include/gnuradio/zeromq/pub_msg_sink.h @@ -52,6 +52,11 @@ namespace gr { * \param timeout Receive timeout in milliseconds, default is 100ms, 1us increments */ static sptr make(char *address, int timeout=100); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/pub_sink.h b/gr-zeromq/include/gnuradio/zeromq/pub_sink.h index 3fecc10b59..d6a03c7f89 100644 --- a/gr-zeromq/include/gnuradio/zeromq/pub_sink.h +++ b/gr-zeromq/include/gnuradio/zeromq/pub_sink.h @@ -57,6 +57,11 @@ namespace gr { */ static sptr make(size_t itemsize, size_t vlen, char *address, int timeout=100, bool pass_tags=false, int hwm=-1); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/pull_msg_source.h b/gr-zeromq/include/gnuradio/zeromq/pull_msg_source.h index 13857ead5f..a0fe8e880f 100644 --- a/gr-zeromq/include/gnuradio/zeromq/pull_msg_source.h +++ b/gr-zeromq/include/gnuradio/zeromq/pull_msg_source.h @@ -50,6 +50,11 @@ namespace gr { * */ static sptr make(char *address, int timeout=100); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/pull_source.h b/gr-zeromq/include/gnuradio/zeromq/pull_source.h index ecfe508b0a..47628cf20d 100644 --- a/gr-zeromq/include/gnuradio/zeromq/pull_source.h +++ b/gr-zeromq/include/gnuradio/zeromq/pull_source.h @@ -54,6 +54,11 @@ namespace gr { */ static sptr make(size_t itemsize, size_t vlen, char *address, int timeout=100, bool pass_tags=false, int hwm=-1); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/push_msg_sink.h b/gr-zeromq/include/gnuradio/zeromq/push_msg_sink.h index 941ad549f5..d13ddfe708 100644 --- a/gr-zeromq/include/gnuradio/zeromq/push_msg_sink.h +++ b/gr-zeromq/include/gnuradio/zeromq/push_msg_sink.h @@ -52,6 +52,11 @@ namespace gr { * */ static sptr make(char *address, int timeout=100); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/push_sink.h b/gr-zeromq/include/gnuradio/zeromq/push_sink.h index f81dcaa941..3cb52535f9 100644 --- a/gr-zeromq/include/gnuradio/zeromq/push_sink.h +++ b/gr-zeromq/include/gnuradio/zeromq/push_sink.h @@ -58,6 +58,11 @@ namespace gr { */ static sptr make(size_t itemsize, size_t vlen, char *address, int timeout=100, bool pass_tags=false, int hwm=-1); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/rep_msg_sink.h b/gr-zeromq/include/gnuradio/zeromq/rep_msg_sink.h index d11550d149..e84964a74b 100644 --- a/gr-zeromq/include/gnuradio/zeromq/rep_msg_sink.h +++ b/gr-zeromq/include/gnuradio/zeromq/rep_msg_sink.h @@ -52,6 +52,11 @@ namespace gr { * */ static sptr make(char *address, int timeout=100); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/rep_sink.h b/gr-zeromq/include/gnuradio/zeromq/rep_sink.h index c1d2d370fc..138d0f13da 100644 --- a/gr-zeromq/include/gnuradio/zeromq/rep_sink.h +++ b/gr-zeromq/include/gnuradio/zeromq/rep_sink.h @@ -56,6 +56,11 @@ namespace gr { */ static sptr make(size_t itemsize, size_t vlen, char *address, int timeout=100, bool pass_tags=false, int hwm=-1); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/req_msg_source.h b/gr-zeromq/include/gnuradio/zeromq/req_msg_source.h index 28ac9f84f3..80a6ae559e 100644 --- a/gr-zeromq/include/gnuradio/zeromq/req_msg_source.h +++ b/gr-zeromq/include/gnuradio/zeromq/req_msg_source.h @@ -50,6 +50,11 @@ namespace gr { * */ static sptr make(char *address, int timeout=100); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/req_source.h b/gr-zeromq/include/gnuradio/zeromq/req_source.h index 103da90f71..dfe3929ebf 100644 --- a/gr-zeromq/include/gnuradio/zeromq/req_source.h +++ b/gr-zeromq/include/gnuradio/zeromq/req_source.h @@ -54,6 +54,11 @@ namespace gr { */ static sptr make(size_t itemsize, size_t vlen, char *address, int timeout=100, bool pass_tags=false, int hwm=-1); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/sub_msg_source.h b/gr-zeromq/include/gnuradio/zeromq/sub_msg_source.h index 5c91d1e1ed..ac68e8aa59 100644 --- a/gr-zeromq/include/gnuradio/zeromq/sub_msg_source.h +++ b/gr-zeromq/include/gnuradio/zeromq/sub_msg_source.h @@ -50,6 +50,11 @@ namespace gr { * */ static sptr make(char *address, int timeout=100); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/include/gnuradio/zeromq/sub_source.h b/gr-zeromq/include/gnuradio/zeromq/sub_source.h index 990c74cabd..874730403f 100644 --- a/gr-zeromq/include/gnuradio/zeromq/sub_source.h +++ b/gr-zeromq/include/gnuradio/zeromq/sub_source.h @@ -54,6 +54,11 @@ namespace gr { */ static sptr make(size_t itemsize, size_t vlen, char *address, int timeout=100, bool pass_tags=false, int hwm=-1); + + /*! + * \brief Return a std::string of ZMQ_LAST_ENDPOINT from the underlying ZMQ socket. + */ + virtual std::string last_endpoint() = 0; }; } // namespace zeromq diff --git a/gr-zeromq/lib/base_impl.cc b/gr-zeromq/lib/base_impl.cc index 20c5d3845d..cd1825141b 100644 --- a/gr-zeromq/lib/base_impl.cc +++ b/gr-zeromq/lib/base_impl.cc @@ -54,6 +54,15 @@ namespace gr { delete d_context; } + std::string + base_impl::last_endpoint() + { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } + base_sink_impl::base_sink_impl(int type, size_t itemsize, size_t vlen, char *address, int timeout, bool pass_tags, int hwm) : base_impl(type, itemsize, vlen, timeout, pass_tags) diff --git a/gr-zeromq/lib/base_impl.h b/gr-zeromq/lib/base_impl.h index ed1695102e..e09e652768 100644 --- a/gr-zeromq/lib/base_impl.h +++ b/gr-zeromq/lib/base_impl.h @@ -37,6 +37,7 @@ namespace gr { virtual ~base_impl(); protected: + std::string last_endpoint(); zmq::context_t *d_context; zmq::socket_t *d_socket; size_t d_vsize; diff --git a/gr-zeromq/lib/pub_msg_sink_impl.h b/gr-zeromq/lib/pub_msg_sink_impl.h index 747ac7ee85..c421361e18 100644 --- a/gr-zeromq/lib/pub_msg_sink_impl.h +++ b/gr-zeromq/lib/pub_msg_sink_impl.h @@ -41,6 +41,12 @@ namespace gr { ~pub_msg_sink_impl(); void handler(pmt::pmt_t msg); + std::string last_endpoint() override { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } }; } // namespace zeromq diff --git a/gr-zeromq/lib/pub_sink_impl.h b/gr-zeromq/lib/pub_sink_impl.h index 8637c3565a..78b5c1e1bd 100644 --- a/gr-zeromq/lib/pub_sink_impl.h +++ b/gr-zeromq/lib/pub_sink_impl.h @@ -39,6 +39,7 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + std::string last_endpoint() override {return base_sink_impl::last_endpoint();} }; } // namespace zeromq diff --git a/gr-zeromq/lib/pull_msg_source_impl.h b/gr-zeromq/lib/pull_msg_source_impl.h index 972dab5aff..4c28a65e56 100644 --- a/gr-zeromq/lib/pull_msg_source_impl.h +++ b/gr-zeromq/lib/pull_msg_source_impl.h @@ -48,6 +48,13 @@ namespace gr { bool start(); bool stop(); + + std::string last_endpoint() override { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } }; } // namespace zeromq diff --git a/gr-zeromq/lib/pull_source_impl.h b/gr-zeromq/lib/pull_source_impl.h index 7d8ab53bd0..c08ab0521b 100644 --- a/gr-zeromq/lib/pull_source_impl.h +++ b/gr-zeromq/lib/pull_source_impl.h @@ -39,6 +39,7 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + std::string last_endpoint() override {return base_source_impl::last_endpoint();} }; } // namespace zeromq diff --git a/gr-zeromq/lib/push_msg_sink_impl.h b/gr-zeromq/lib/push_msg_sink_impl.h index d669d327cb..2cd487d743 100644 --- a/gr-zeromq/lib/push_msg_sink_impl.h +++ b/gr-zeromq/lib/push_msg_sink_impl.h @@ -41,6 +41,12 @@ namespace gr { ~push_msg_sink_impl(); void handler(pmt::pmt_t msg); + std::string last_endpoint() override { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } }; } // namespace zeromq diff --git a/gr-zeromq/lib/push_sink_impl.h b/gr-zeromq/lib/push_sink_impl.h index 0a5de10787..73480e1047 100644 --- a/gr-zeromq/lib/push_sink_impl.h +++ b/gr-zeromq/lib/push_sink_impl.h @@ -39,6 +39,8 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + + std::string last_endpoint() override {return base_sink_impl::last_endpoint();} }; } // namespace zeromq diff --git a/gr-zeromq/lib/rep_msg_sink_impl.h b/gr-zeromq/lib/rep_msg_sink_impl.h index a8485304d7..7b13e93952 100644 --- a/gr-zeromq/lib/rep_msg_sink_impl.h +++ b/gr-zeromq/lib/rep_msg_sink_impl.h @@ -48,6 +48,13 @@ namespace gr { bool start(); bool stop(); + + std::string last_endpoint() override { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } }; } // namespace zeromq diff --git a/gr-zeromq/lib/rep_sink_impl.h b/gr-zeromq/lib/rep_sink_impl.h index 012fc45e7b..b9451cfeaf 100644 --- a/gr-zeromq/lib/rep_sink_impl.h +++ b/gr-zeromq/lib/rep_sink_impl.h @@ -39,6 +39,7 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + std::string last_endpoint() override {return base_sink_impl::last_endpoint();} }; } // namespace zeromq diff --git a/gr-zeromq/lib/req_msg_source_impl.h b/gr-zeromq/lib/req_msg_source_impl.h index 322ce4cf51..61d80104d1 100644 --- a/gr-zeromq/lib/req_msg_source_impl.h +++ b/gr-zeromq/lib/req_msg_source_impl.h @@ -48,6 +48,13 @@ namespace gr { bool start(); bool stop(); + + std::string last_endpoint() override { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } }; } // namespace zeromq diff --git a/gr-zeromq/lib/req_source_impl.h b/gr-zeromq/lib/req_source_impl.h index 8bdbd33459..ec87832518 100644 --- a/gr-zeromq/lib/req_source_impl.h +++ b/gr-zeromq/lib/req_source_impl.h @@ -40,6 +40,7 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + std::string last_endpoint() override {return base_source_impl::last_endpoint();} private: bool d_req_pending; }; diff --git a/gr-zeromq/lib/sub_msg_source_impl.h b/gr-zeromq/lib/sub_msg_source_impl.h index 4cf85d10ba..e1c2e07788 100644 --- a/gr-zeromq/lib/sub_msg_source_impl.h +++ b/gr-zeromq/lib/sub_msg_source_impl.h @@ -48,6 +48,13 @@ namespace gr { bool start(); bool stop(); + + std::string last_endpoint() override { + size_t addr_len = 256; + char addr[addr_len]; + d_socket->getsockopt(ZMQ_LAST_ENDPOINT, addr, &addr_len); + return std::string(addr, addr_len-1); + } }; } // namespace zeromq diff --git a/gr-zeromq/lib/sub_source_impl.h b/gr-zeromq/lib/sub_source_impl.h index 8f82a9ab94..727d76d6a2 100644 --- a/gr-zeromq/lib/sub_source_impl.h +++ b/gr-zeromq/lib/sub_source_impl.h @@ -39,6 +39,8 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + + std::string last_endpoint() override {return base_source_impl::last_endpoint();} }; } // namespace zeromq |