Commit c0d766d2 authored by Joseph Noir's avatar Joseph Noir

Add some convenience functions

parent 43f9d975
......@@ -251,6 +251,17 @@ public:
/// Returns the handle associated to given local `port` or `none`.
accept_handle hdl_by_port(uint16_t port);
/// Returns the remote address associated to `hdl`
/// or empty string if `hdl` is invalid.
std::string remote_addr(datagram_sink_handle hdl);
/// Returns the remote port associated to `hdl`
/// or `0` if `hdl` is invalid.
uint16_t remote_port(datagram_sink_handle hdl);
/// Returns the local port associated to `hdl` or `0` if `hdl` is invalid.
uint16_t local_port(datagram_source_handle hdl);
/// Closes all connections and acceptors.
void close_all();
......
......@@ -230,6 +230,21 @@ uint16_t abstract_broker::local_port(accept_handle hdl) {
return i != doormen_.end() ? i->second->port() : 0;
}
std::string abstract_broker::remote_addr(datagram_sink_handle hdl) {
auto i = datagram_sinks_.find(hdl);
return i != datagram_sinks_.end() ? i->second->addr() : std::string{};
}
uint16_t abstract_broker::remote_port(datagram_sink_handle hdl) {
auto i = datagram_sinks_.find(hdl);
return i != datagram_sinks_.end() ? i->second->port() : 0;
}
uint16_t abstract_broker::local_port(datagram_source_handle hdl) {
auto i = datagram_sources_.find(hdl);
return i != datagram_sources_.end() ? i->second->port() : 0;
}
accept_handle abstract_broker::hdl_by_port(uint16_t port) {
for (auto& kvp : doormen_)
if (kvp.second->port() == port)
......@@ -247,6 +262,14 @@ void abstract_broker::close_all() {
// stop_reading will remove the scribe from scribes_
scribes_.begin()->second->stop_reading();
}
while (!datagram_sinks_.empty()) {
// stop_reading will remove the datagram_sink from datagram_sinks_
datagram_sinks_.begin()->second->stop_reading();
}
while (!datagram_sources_.empty()) {
// stop_reading will remove the datgram_source from datgram_sources_
datagram_sources_.begin()->second->stop_reading();
}
}
resumable::subtype_t abstract_broker::subtype() const {
......
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