Commit 0696b6aa authored by Joseph Noir's avatar Joseph Noir

Add dgram_{scribe,doorman} impl in def multiplexer

parent 211c30f4
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
using dgram_doorman_base::new_endpoint; using dgram_doorman_base::new_endpoint;
bool new_endpoint(execution_unit* ctx, const void*, size_t num_bytes); bool new_endpoint(execution_unit* ctx, dgram_scribe_handle endpoint);
// needs to be launched explicitly // needs to be launched explicitly
virtual void launch() = 0; virtual void launch() = 0;
......
...@@ -389,6 +389,9 @@ private: ...@@ -389,6 +389,9 @@ private:
void wr_dispatch_request(resumable* ptr); void wr_dispatch_request(resumable* ptr);
// allows initialization of scribes with an exisiting sockaddr
dgram_scribe_handle add_dgram_scribe(abstract_broker* ptr, native_socket fd,
sockaddr_storage* addr, size_t len);
//resumable* rd_dispatch_request(); //resumable* rd_dispatch_request();
native_socket epollfd_; // unused in poll() implementation native_socket epollfd_; // unused in poll() implementation
...@@ -607,6 +610,8 @@ public: ...@@ -607,6 +610,8 @@ public:
void sender_from_sockaddr(sockaddr_storage& sa, size_t len); void sender_from_sockaddr(sockaddr_storage& sa, size_t len);
void set_endpoint_addr(sockaddr_storage& sa, size_t len);
private: private:
void prepare_next_read(); void prepare_next_read();
...@@ -616,6 +621,7 @@ private: ...@@ -616,6 +621,7 @@ private:
manager_ptr reader_; manager_ptr reader_;
size_t dgram_size_; size_t dgram_size_;
buffer_type rd_buf_; buffer_type rd_buf_;
size_t bytes_read_;
// state for writing // state for writing
manager_ptr writer_; manager_ptr writer_;
...@@ -626,7 +632,7 @@ private: ...@@ -626,7 +632,7 @@ private:
buffer_type wr_offline_buf_; buffer_type wr_offline_buf_;
// general state // general state
struct sockaddr_storage remote_endpoint_; struct sockaddr_storage sockaddr_;
socklen_t sockaddr_len_; socklen_t sockaddr_len_;
std::string host_; std::string host_;
uint16_t port_; uint16_t port_;
...@@ -683,11 +689,13 @@ public: ...@@ -683,11 +689,13 @@ public:
void sender_from_sockaddr(sockaddr_storage& sa, size_t len); void sender_from_sockaddr(sockaddr_storage& sa, size_t len);
std::pair<sockaddr_storage*,size_t> last_sender();
private: private:
void prepare_next_read(); void prepare_next_read();
// reader state // reader state
manager_ptr reader_; manager_ptr mgr_;
size_t dgram_size_; size_t dgram_size_;
buffer_type rd_buf_; buffer_type rd_buf_;
...@@ -696,7 +704,7 @@ private: ...@@ -696,7 +704,7 @@ private:
socklen_t sockaddr_len_; socklen_t sockaddr_len_;
std::string host_; std::string host_;
uint16_t port_; uint16_t port_;
native_socket sock_; // TODO: Do I need this? // native_socket sock_; // TODO: Do I need this?
}; };
expected<native_socket> new_tcp_connection(const std::string& host, expected<native_socket> new_tcp_connection(const std::string& host,
......
...@@ -111,6 +111,9 @@ public: ...@@ -111,6 +111,9 @@ public:
/// Returns the output buffer of the datagram source identified by `hdl`. /// Returns the output buffer of the datagram source identified by `hdl`.
buffer_type& output_buffer(dgram_scribe_handle hdl); buffer_type& output_buffer(dgram_scribe_handle hdl);
/// Returns the input buffer of the scribe identified by `hdl`.
buffer_type& input_buffer(dgram_scribe_handle hdl);
/// Returns the input buffer of the scribe identified by `hdl`. /// Returns the input buffer of the scribe identified by `hdl`.
buffer_type& input_buffer(connection_handle hdl); buffer_type& input_buffer(connection_handle hdl);
......
...@@ -156,28 +156,30 @@ inspect(Inspector& f, dgram_doorman_closed_msg& x) { ...@@ -156,28 +156,30 @@ inspect(Inspector& f, dgram_doorman_closed_msg& x) {
struct new_endpoint_msg { struct new_endpoint_msg {
/// Handle to the related datagram endpoint. /// Handle to the related datagram endpoint.
dgram_doorman_handle handle; dgram_doorman_handle handle;
/// Buffer containing the received data. // Buffer containing the received data.
std::vector<char> buf; // std::vector<char> buf;
/// Handle to new dgram_scribe
dgram_scribe_handle endpoint;
}; };
/// @relates new_endpoint_msg /// @relates new_endpoint_msg
template <class Inspector> template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, new_endpoint_msg& x) { typename Inspector::result_type inspect(Inspector& f, new_endpoint_msg& x) {
return f(meta::type_name("new_endpoint_msg"), x.handle, x.buf); return f(meta::type_name("new_endpoint_msg"), x.handle, x.endpoint);
} }
/// Signalizes that a datagram with a certain size has been sent. /// Signalizes that a datagram with a certain size has been sent.
struct new_datagram_msg { struct new_datagram_msg {
// Handle to the endpoint used. // Handle to the endpoint used.
dgram_scribe_handle handle; dgram_scribe_handle handle;
// number of bytes written. // Buffer containing received data.
uint64_t written; std::vector<char> buf;
}; };
/// @relates new_datagram_msg /// @relates new_datagram_msg
template <class Inspector> template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, new_datagram_msg& x) { typename Inspector::result_type inspect(Inspector& f, new_datagram_msg& x) {
return f(meta::type_name("new_datagram_msg"), x.handle, x.written); return f(meta::type_name("new_datagram_msg"), x.handle, x.buf);
} }
/// Signalizes that a datagram with a certain size has been sent. /// Signalizes that a datagram with a certain size has been sent.
......
This diff is collapsed.
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
namespace caf { namespace caf {
namespace io { namespace io {
dgram_doorman::dgram_doorman(abstract_broker* parent, dgram_doorman::dgram_doorman(abstract_broker* parent, dgram_doorman_handle hdl)
dgram_doorman_handle hdl)
: dgram_doorman_base(parent, hdl) { : dgram_doorman_base(parent, hdl) {
// nop // nop
} }
...@@ -45,10 +44,12 @@ void dgram_doorman::io_failure(execution_unit* ctx, network::operation op) { ...@@ -45,10 +44,12 @@ void dgram_doorman::io_failure(execution_unit* ctx, network::operation op) {
detach(ctx, true); detach(ctx, true);
} }
bool dgram_doorman::new_endpoint(execution_unit* ctx, const void* buf, // bool dgram_doorman::new_endpoint(execution_unit* ctx, const void* buf,
size_t besize) { // size_t besize) {
// TODO: implement me! bool dgram_doorman::new_endpoint(execution_unit* ctx,
return false; dgram_scribe_handle endpoint) {
msg().endpoint = endpoint;
return invoke_mailbox_element(ctx);
} }
} // namespace io } // namespace io
......
...@@ -37,8 +37,7 @@ message dgram_scribe::detach_message() { ...@@ -37,8 +37,7 @@ message dgram_scribe::detach_message() {
return make_message(dgram_scribe_closed_msg{hdl()}); return make_message(dgram_scribe_closed_msg{hdl()});
} }
bool dgram_scribe::consume(execution_unit* ctx, const void*, bool dgram_scribe::consume(execution_unit* ctx, const void*, size_t num_bytes) {
size_t num_bytes) {
CAF_ASSERT(ctx != nullptr); CAF_ASSERT(ctx != nullptr);
CAF_LOG_TRACE(CAF_ARG(num_bytes)); CAF_LOG_TRACE(CAF_ARG(num_bytes));
if (detached()) if (detached())
......
...@@ -165,8 +165,7 @@ public: ...@@ -165,8 +165,7 @@ public:
} else if (std::distance(u.scheme().first, u.scheme().second) >= 3 && } else if (std::distance(u.scheme().first, u.scheme().second) >= 3 &&
equal(std::begin(udp), std::end(udp), u.scheme().first)) { equal(std::begin(udp), std::end(udp), u.scheme().first)) {
// connect to endpoint and initiate handhsake etc. (UDP) // connect to endpoint and initiate handhsake etc. (UDP)
auto y auto y = system().middleman().backend().new_dgram_scribe(host, port);
= system().middleman().backend().new_remote_endpoint(host, port);
if (!y) { if (!y) {
rp.deliver(std::move(y.error())); rp.deliver(std::move(y.error()));
return {}; return {};
...@@ -257,11 +256,11 @@ private: ...@@ -257,11 +256,11 @@ private:
equal(u.scheme().first, u.scheme().second, std::begin(udp))) { equal(u.scheme().first, u.scheme().second, std::begin(udp))) {
// UDP // UDP
auto res auto res
= system().middleman().backend().new_local_endpoint(u.port_as_int(), = system().middleman().backend().new_dgram_doorman(u.port_as_int(),
in, reuse_addr); in, reuse_addr);
if (!res) if (!res)
return std::move(res.error()); return std::move(res.error());
endpoint_handle hdl = res->first; dgram_doorman_handle hdl = res->first;
actual_port = res->second; actual_port = res->second;
anon_send(broker_, publish_atom::value, hdl, actual_port, anon_send(broker_, publish_atom::value, hdl, actual_port,
std::move(whom), std::move(sigs)); std::move(whom), std::move(sigs));
......
...@@ -236,34 +236,52 @@ expected<void> test_multiplexer::assign_dgram_scribe(abstract_broker* ptr, ...@@ -236,34 +236,52 @@ expected<void> test_multiplexer::assign_dgram_scribe(abstract_broker* ptr,
mpx_(mpx) { mpx_(mpx) {
// nop // nop
} }
void configure_datagram_size(size_t buf_size) override { void configure_datagram_size(size_t buf_size) override {
mpx_->buffer_size(hdl()) = buf_size; mpx_->buffer_size(hdl()) = buf_size;
} }
void stop_reading() override { void stop_reading() override {
mpx_->stopped_reading(hdl()) = true; mpx_->stopped_reading(hdl()) = true;
detach(mpx_, false); detach(mpx_, false);
} }
void ack_writes(bool enable) override { void ack_writes(bool enable) override {
mpx_->ack_writes(hdl()) = enable; mpx_->ack_writes(hdl()) = enable;
} }
std::vector<char>& rd_buf() override {
return mpx_->input_buffer(hdl());
}
std::vector<char>& wr_buf() override { std::vector<char>& wr_buf() override {
return mpx_->output_buffer(hdl()); return mpx_->output_buffer(hdl());
} }
std::string addr() const override { std::string addr() const override {
return "test"; return "test";
} }
uint16_t port() const override { uint16_t port() const override {
return mpx_->port(hdl()); return mpx_->port(hdl());
} }
void launch() { void launch() {
// nop // nop
} }
void flush() override {
// nop
}
void add_to_loop() override { void add_to_loop() override {
mpx_->passive_mode(hdl()) = false; mpx_->passive_mode(hdl()) = false;
} }
void remove_from_loop() override { void remove_from_loop() override {
mpx_->passive_mode(hdl()) = true; mpx_->passive_mode(hdl()) = true;
} }
private: private:
test_multiplexer* mpx_; test_multiplexer* mpx_;
}; };
...@@ -311,31 +329,55 @@ expected<void> test_multiplexer::assign_dgram_doorman(abstract_broker* ptr, ...@@ -311,31 +329,55 @@ expected<void> test_multiplexer::assign_dgram_doorman(abstract_broker* ptr,
mpx_(mpx) { mpx_(mpx) {
// nop // nop
} }
bool new_endpoint() override {
// TODO: Implement me
/*
auto& mm = mpx_->pending_connects();
auto i = mm.find(hdl());
bool result = true;
if (i != mm.end()) {
result = doorman::new_connection(mpx_, i->second);
mm.erase(i);
}
return result;
*/
return false;
}
void configure_datagram_size(size_t buf_size) override { void configure_datagram_size(size_t buf_size) override {
mpx_->buffer_size(hdl()) = buf_size; mpx_->buffer_size(hdl()) = buf_size;
} }
void stop_reading() override { void stop_reading() override {
mpx_->stopped_reading(hdl()) = true; mpx_->stopped_reading(hdl()) = true;
detach(mpx_, false); detach(mpx_, false);
} }
std::vector<char>& rd_buf() override { std::vector<char>& rd_buf() override {
return mpx_->input_buffer(hdl()); return mpx_->input_buffer(hdl());
} }
std::string addr() const override { std::string addr() const override {
return "test"; return "test";
} }
uint16_t port() const override { uint16_t port() const override {
return mpx_->port(hdl()); return mpx_->port(hdl());
} }
void launch() override { void launch() override {
// nop // nop
} }
void add_to_loop() override { void add_to_loop() override {
mpx_->passive_mode(hdl()) = false; mpx_->passive_mode(hdl()) = false;
} }
void remove_from_loop() override { void remove_from_loop() override {
mpx_->passive_mode(hdl()) = true; mpx_->passive_mode(hdl()) = true;
} }
private: private:
test_multiplexer* mpx_; test_multiplexer* mpx_;
}; };
...@@ -437,6 +479,11 @@ uint16_t& test_multiplexer::port(accept_handle hdl) { ...@@ -437,6 +479,11 @@ uint16_t& test_multiplexer::port(accept_handle hdl) {
return doorman_data_[hdl].port; return doorman_data_[hdl].port;
} }
test_multiplexer::buffer_type&
test_multiplexer::input_buffer(dgram_scribe_handle hdl) {
return dgram_scribe_data_[hdl].rd_buf;
}
test_multiplexer::buffer_type& test_multiplexer::buffer_type&
test_multiplexer::output_buffer(dgram_scribe_handle hdl) { test_multiplexer::output_buffer(dgram_scribe_handle hdl) {
return dgram_scribe_data_[hdl].wr_buf; return dgram_scribe_data_[hdl].wr_buf;
......
...@@ -72,34 +72,34 @@ behavior make_pong_behavior() { ...@@ -72,34 +72,34 @@ behavior make_pong_behavior() {
} // namespace <anonymous> } // namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE(datagrams, fixture) CAF_TEST_FIXTURE_SCOPE(datagrams, fixture)
/*
CAF_TEST(test_remote_endpoint) { CAF_TEST(test_dgram_scribe) {
auto& mp = client_side_mm.backend(); auto& mp = client_side_mm.backend();
auto hdl = client_side_mm.named_broker<basp_broker>(atom("BASP")); auto hdl = client_side_mm.named_broker<basp_broker>(atom("BASP"));
auto basp = static_cast<basp_broker*>(actor_cast<abstract_actor*>(hdl)); auto basp = static_cast<basp_broker*>(actor_cast<abstract_actor*>(hdl));
CAF_MESSAGE("Calling new_remote_endpoint"); CAF_MESSAGE("Calling new_remote_endpoint");
auto res1 = mp.new_remote_endpoint(host, port + 0); auto res1 = mp.new_dgram_scribe(host, port + 0);
CAF_REQUIRE(res1); CAF_REQUIRE(res1);
CAF_MESSAGE("Calling assign_endpoint (on \"remote\" endpoint)."); CAF_MESSAGE("Calling assign_endpoint (on \"remote\" endpoint).");
auto res2 = mp.assign_endpoint(basp, *res1); auto res2 = mp.assign_dgram_scribe(basp, *res1);
CAF_REQUIRE(res2); CAF_REQUIRE(res2);
CAF_MESSAGE("Calling add_remote_endpoint."); CAF_MESSAGE("Calling add_remote_endpoint.");
auto res3 = mp.add_remote_endpoint(basp, host, port + 1); auto res3 = mp.add_dgram_scribe(basp, host, port + 1);
CAF_REQUIRE(res3); CAF_REQUIRE(res3);
} }
CAF_TEST(test_local_endpoint) { CAF_TEST(test_dgram_doorman) {
auto& mp = client_side_mm.backend(); auto& mp = client_side_mm.backend();
auto hdl = client_side_mm.named_broker<basp_broker>(atom("BASP")); auto hdl = client_side_mm.named_broker<basp_broker>(atom("BASP"));
auto basp = static_cast<basp_broker*>(actor_cast<abstract_actor*>(hdl)); auto basp = static_cast<basp_broker*>(actor_cast<abstract_actor*>(hdl));
CAF_MESSAGE("Calling new_local_endpoint."); CAF_MESSAGE("Calling new_local_endpoint.");
auto res1 = mp.new_local_endpoint(port + 0); auto res1 = mp.new_dgram_doorman(port + 0);
CAF_REQUIRE(res1); CAF_REQUIRE(res1);
CAF_MESSAGE("Calling assign_endpoint (on \"local\" endpoint)."); CAF_MESSAGE("Calling assign_endpoint (on \"local\" endpoint).");
auto res2 = mp.assign_endpoint(basp, res1->first); auto res2 = mp.assign_dgram_doorman(basp, res1->first);
CAF_REQUIRE(res2); CAF_REQUIRE(res2);
CAF_MESSAGE("Calling add_local_endpoint."); CAF_MESSAGE("Calling add_local_endpoint.");
auto res3 = mp.add_local_endpoint(basp, port + 1, nullptr); auto res3 = mp.add_dgram_doorman(basp, port + 1, nullptr);
CAF_REQUIRE(res3); CAF_REQUIRE(res3);
} }
...@@ -134,5 +134,5 @@ CAF_TEST(test_datagram_remote_actor) { ...@@ -134,5 +134,5 @@ CAF_TEST(test_datagram_remote_actor) {
anon_send_exit(pong, exit_reason::user_shutdown); anon_send_exit(pong, exit_reason::user_shutdown);
} }
*/
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
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