Commit abbd084f authored by Joseph Noir's avatar Joseph Noir

Add datagram functionality to default multiplexer

parent 48b6303a
......@@ -209,7 +209,7 @@ public:
/// Assigns a detached `datagram_sink` instance identified by `hdl`
/// from the `multiplexer` to this broker.
expected<void> assign_datagram_sink(connection_handle hdl);
expected<void> assign_datagram_sink(datagram_sink_handle hdl);
/// Creates and assigns a new `datagram_sink` from given native socked `fd`.
expected<datagram_sink_handle> add_datagram_sink(network::native_socket fd);
......@@ -227,7 +227,7 @@ public:
/// Assigns a detached `datagram_source` instance identified by `hdl`
/// from the `multiplexer` to this broker.
expected<void> assign_datagram_source(accept_handle hdl);
expected<void> assign_datagram_source(datagram_source_handle hdl);
/// Creates and assigns a new `datagram_source` from given native socked `fd`.
expected<datagram_source_handle>
......
......@@ -44,10 +44,8 @@ public:
~datagram_source();
/*
/// Implicitly starts the read loop on first call.
virtual void configure_read(receive_policy::config config) = 0;
*/
virtual void configure_datagram_size(size_t buf_size) = 0;
/// Returns the current input buffer.
virtual std::vector<char>& rd_buf() = 0;
......
......@@ -532,13 +532,6 @@ private:
native_socket sock_;
};
expected<native_socket> new_tcp_connection(const std::string& host,
uint16_t port,
optional<protocol> preferred = none);
expected<std::pair<native_socket, uint16_t>>
new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr);
/// A datagram_sender is responsible for sending datagrams to an endpoint.
class datagram_sender: public event_handler {
public:
......@@ -591,8 +584,6 @@ private:
manager_ptr writer_;
bool ack_writes_;
bool writing_;
size_t written_;
buffer_type wr_buf_;
buffer_type wr_offline_buf_;
};
......@@ -612,6 +603,11 @@ public:
datagram_receiver(default_multiplexer& backend_ref, native_socket sockfd);
/// Configures how much buffer will be provided for the next datagram.
/// @warning Must not be called outside the IO multiplexers event loop
/// once the stream has been started.
void configure_datagram_size(size_t buf_size);
/// Returns the read buffer of this datagram receiver.
/// @warning Must not be modified outside the IO multiplexers event loop
/// once the stream has been started.
......@@ -634,14 +630,27 @@ public:
void handle_event(operation op) override;
private:
void prepare_next_read();
manager_ptr reader_;
size_t read_threshold_;
size_t collected_;
size_t max_;
size_t buf_size_;
size_t packet_size_;
buffer_type rd_buf_;
struct sockaddr_storage last_sender;
socklen_t sender_len;
};
expected<native_socket> new_tcp_connection(const std::string& host,
uint16_t port,
optional<protocol> preferred = none);
expected<std::pair<native_socket, uint16_t>>
new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr);
expected<native_socket>
new_datagram_sink_impl(const std::string& host, uint16_t port,
optional<protocol> preferred = none);
} // namespace network
} // namespace io
} // namespace caf
......
......@@ -164,6 +164,52 @@ abstract_broker::add_tcp_doorman(network::native_socket fd) {
return backend().add_tcp_doorman(this, fd);
}
void abstract_broker::add_datagram_sink(const intrusive_ptr<datagram_sink>& ptr) {
datagram_sinks_.emplace(ptr->hdl(), ptr);
}
expected<datagram_sink_handle>
abstract_broker::add_datagram_sink(const std::string& hostname, uint16_t port) {
CAF_LOG_TRACE(CAF_ARG(hostname) << CAF_ARG(port));
return backend().add_datagram_sink(this, hostname, port);
}
expected<void> abstract_broker::assign_datagram_sink(datagram_sink_handle hdl) {
CAF_LOG_TRACE(CAF_ARG(hdl));
return backend().assign_datagram_sink(this, hdl);
}
expected<datagram_sink_handle>
abstract_broker::add_datagram_sink(network::native_socket fd) {
CAF_LOG_TRACE(CAF_ARG(fd));
return backend().add_datagram_sink(this, fd);
}
void
abstract_broker::add_datagram_source(const intrusive_ptr<datagram_source>& ptr) {
datagram_sources_.emplace(ptr->hdl(), ptr);
// TODO: some launching of things?
}
expected<std::pair<datagram_source_handle, uint16_t>>
abstract_broker::add_datagram_source(uint16_t port, const char* in,
bool reuse_addr) {
CAF_LOG_TRACE(CAF_ARG(port) << CAF_ARG(in) << CAF_ARG(reuse_addr));
return backend().add_datagram_source(this, port, in, reuse_addr);
}
expected<void>
abstract_broker::assign_datagram_source(datagram_source_handle hdl) {
CAF_LOG_TRACE(CAF_ARG(hdl));
return backend().assign_datagram_source(this, hdl);
}
expected<datagram_source_handle>
abstract_broker::add_datagram_source(network::native_socket fd) {
CAF_LOG_TRACE(CAF_ARG(fd));
return backend().add_datagram_source(this, fd);
}
std::string abstract_broker::remote_addr(connection_handle hdl) {
auto i = scribes_.find(hdl);
return i != scribes_.end() ? i->second->addr() : std::string{};
......
This diff is collapsed.
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