Commit eee3d7e7 authored by Joseph Noir's avatar Joseph Noir

Fix remote address lookup for datagram handles

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