Commit 73c5517a authored by Jakob Otto's avatar Jakob Otto

Change scribe/scribe-test to match new application-policy api

parent 0f680b85
......@@ -18,7 +18,7 @@ set(LIBCAF_NET_SRCS
src/socket.cpp
src/socket_manager.cpp
src/stream_socket.cpp
src/scribe.cpp
src/scribe.cpp
)
add_custom_target(libcaf_net)
......
......@@ -25,16 +25,15 @@
#include <caf/net/receive_policy.hpp>
#include <caf/net/stream_socket.hpp>
#include <caf/sec.hpp>
#include <caf/span.hpp>
#include <caf/variant.hpp>
#ifdef CAF_WINDOWS
# include <winsock2.h>
#else
# include <caf/actor.hpp>
# include <sys/socket.h>
# include <sys/types.h>
#endif
namespace caf {
......@@ -42,16 +41,7 @@ namespace policy {
class scribe {
public:
explicit scribe(net::stream_socket handle)
: handle_(handle),
max_consecutive_reads_(0),
read_threshold_(1024),
collected_(0),
max_(1024),
rd_flag_(net::receive_policy_flag::exactly),
written_(0) {
// nop
}
explicit scribe(net::stream_socket handle);
net::stream_socket handle_;
......@@ -76,7 +66,7 @@ public:
CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(*num_bytes));
collected_ += *num_bytes;
if (collected_ >= read_threshold_) {
parent.application().process(read_buf_, *this, parent);
parent.application().handle_data(*this, read_buf_);
prepare_next_read();
return false;
} else {
......@@ -98,7 +88,7 @@ public:
// get new data from parent
for (auto msg = parent.next_message(); msg != nullptr;
msg = parent.next_message()) {
parent.application().prepare(std::move(msg), *this);
parent.application().write_message(*this, std::move(msg));
}
// write prepared data
return write_some(parent);
......@@ -151,7 +141,7 @@ public:
void configure_read(net::receive_policy::config cfg);
std::vector<char>& wr_buf();
void write_packet(span<char> buf);
private:
std::vector<char> read_buf_;
......
......@@ -21,11 +21,21 @@
#include <system_error>
#include "caf/config.hpp"
#include "caf/variant.hpp"
namespace caf {
namespace policy {
scribe::scribe(caf::net::stream_socket handle)
: handle_(handle),
max_consecutive_reads_(0),
read_threshold_(1024),
collected_(0),
max_(1024),
rd_flag_(net::receive_policy_flag::exactly),
written_(0) {
// nop
}
void scribe::prepare_next_read() {
collected_ = 0;
// This cast does nothing, but prevents a weird compiler error on GCC <= 4.9.
......@@ -58,8 +68,8 @@ void scribe::configure_read(net::receive_policy::config cfg) {
prepare_next_read();
}
std::vector<char>& scribe::wr_buf() {
return write_buf_;
void scribe::write_packet(span<char> buf) {
write_buf_.insert(write_buf_.end(), buf.begin(), buf.end());
}
} // namespace policy
......
......@@ -20,6 +20,7 @@
#include "caf/net/endpoint_manager.hpp"
#include <caf/policy/scribe.hpp>
#include <caf/policy/string_application.hpp>
#include "caf/test/dsl.hpp"
......@@ -67,24 +68,22 @@ public:
~dummy_application() = default;
template <class Transport>
void prepare(std::unique_ptr<endpoint_manager::message> msg,
Transport& transport) {
auto& buf = transport.wr_buf();
auto& msg_buf = msg->payload;
buf.resize(msg_buf.size());
buf.insert(buf.begin(), msg_buf.begin(), msg_buf.end());
void write_message(Transport& transport,
std::unique_ptr<endpoint_manager::message> msg) {
transport.write_packet(msg->payload);
}
template <class Transport>
void process(std::vector<char> payload, Transport&, socket_manager&) {
template <class Parent>
void handle_data(Parent&, span<char> data) {
rec_buf_->clear();
rec_buf_->insert(rec_buf_->begin(), payload.begin(), payload.end());
rec_buf_->insert(rec_buf_->begin(), data.begin(), data.end());
}
template <class Manager>
void resolve(Manager& manager, const std::string& path, actor listener) {
actor_id aid = 42;
node_id nid{42, "00112233445566778899aa00112233445566778899aa"};
auto hid = "0011223344556677889900112233445566778899";
auto nid = unbox(make_node_id(42, hid));
actor_config cfg;
auto p = make_actor<actor_proxy_impl, strong_actor_ptr>(aid, nid,
&manager.system(),
......
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