Commit eee3d7e7 authored by Joseph Noir's avatar Joseph Noir

Fix remote address lookup for datagram handles

parent 78f54969
......@@ -36,6 +36,9 @@ public:
/// Get the port of the underlying I/O device.
virtual uint16_t port() const = 0;
/// Get the port of the underlying I/O device.
virtual std::string addr() const = 0;
};
} // namespace caf
......
......@@ -88,6 +88,9 @@ public:
/// once the stream has been started.
void flush(const manager_ptr& mgr);
/// Return the remote address for a given `hdl`.
std::string addr(datagram_handle hdl) const;
void removed_from_loop(operation op) override;
void graceful_shutdown() override;
......
......@@ -47,6 +47,9 @@ public:
/// Get the port of the underlying I/O device.
virtual uint16_t port(datagram_handle) const = 0;
/// Get the remote address of the underlying I/O device.
virtual std::string addr(datagram_handle) const = 0;
};
} // namespace caf
......
......@@ -50,7 +50,7 @@ public:
void flush() override;
std::string addr() const override;
std::string addr(datagram_handle hdl) const override;
uint16_t port(datagram_handle hdl) const override;
......
......@@ -63,9 +63,6 @@ public:
/// Detaches this manager from its parent in case of an error.
void io_failure(execution_unit* ctx, operation op);
/// Get the address of the underlying I/O device.
virtual std::string addr() const = 0;
protected:
/// Creates a message signalizing a disconnect to the parent.
virtual message detach_message() = 0;
......
......@@ -40,6 +40,9 @@ public:
/// Get the port of the underlying I/O device.
virtual uint16_t port() const = 0;
/// Get the address of the underlying I/O device.
virtual std::string addr() const = 0;
};
} // namespace caf
......
......@@ -317,7 +317,7 @@ datagram_handle abstract_broker::datagram_hdl_by_port(uint16_t port) {
std::string abstract_broker::remote_addr(datagram_handle hdl) {
auto i = datagram_servants_.find(hdl);
return i != datagram_servants_.end() ? i->second->addr() : std::string{};
return i != datagram_servants_.end() ? i->second->addr(hdl) : std::string{};
}
uint16_t abstract_broker::remote_port(datagram_handle hdl) {
......
......@@ -122,6 +122,12 @@ void datagram_handler::remove_endpoint(datagram_handle hdl) {
}
}
std::string datagram_handler::addr(datagram_handle hdl) const {
if (auto itr = ep_by_hdl_.find(hdl); itr != ep_by_hdl_.end())
return host(itr->second);
return std::string{};
}
void datagram_handler::removed_from_loop(operation op) {
switch (op) {
case operation::read:
......
......@@ -85,11 +85,8 @@ void datagram_servant_impl::flush() {
handler_.flush(this);
}
std::string datagram_servant_impl::addr() const {
auto x = remote_addr_of_fd(handler_.fd());
if (!x)
return "";
return *x;
std::string datagram_servant_impl::addr(datagram_handle hdl) const {
return handler_.addr(hdl);
}
uint16_t datagram_servant_impl::port(datagram_handle hdl) const {
......
......@@ -371,7 +371,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
void flush() override {
// nop
}
std::string addr() const override {
std::string addr(datagram_handle) const override {
return "test";
}
uint16_t port(datagram_handle dh) const override {
......
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