Commit 6d88253b authored by Jakob Otto's avatar Jakob Otto

Rename scribe-class/file

parent 2b11f632
...@@ -18,7 +18,7 @@ set(LIBCAF_NET_SRCS ...@@ -18,7 +18,7 @@ set(LIBCAF_NET_SRCS
src/socket.cpp src/socket.cpp
src/socket_manager.cpp src/socket_manager.cpp
src/stream_socket.cpp src/stream_socket.cpp
src/scribe_policy.cpp src/scribe.cpp
) )
add_custom_target(libcaf_net) add_custom_target(libcaf_net)
......
...@@ -18,38 +18,37 @@ ...@@ -18,38 +18,37 @@
#pragma once #pragma once
#include <caf/fwd.hpp>
#include <caf/net/stream_socket.hpp>
#include <caf/net/receive_policy.hpp>
#include <caf/error.hpp> #include <caf/error.hpp>
#include <caf/fwd.hpp>
#include <caf/logger.hpp> #include <caf/logger.hpp>
#include <caf/net/endpoint_manager.hpp>
#include <caf/net/receive_policy.hpp>
#include <caf/net/stream_socket.hpp>
#include <caf/sec.hpp> #include <caf/sec.hpp>
#include <caf/variant.hpp> #include <caf/variant.hpp>
#include <caf/net/endpoint_manager.hpp>
#ifdef CAF_WINDOWS #ifdef CAF_WINDOWS
# include <winsock2.h> # include <winsock2.h>
#else #else
# include <sys/types.h> # include <caf/actor.hpp>
# include <sys/socket.h> # include <sys/socket.h>
#include <caf/actor.hpp> # include <sys/types.h>
#endif #endif
namespace caf { namespace caf {
namespace policy { namespace policy {
class scribe_policy { class scribe {
public: public:
explicit scribe_policy(net::stream_socket handle) : explicit scribe(net::stream_socket handle)
handle_(handle), : handle_(handle),
max_consecutive_reads_(0), max_consecutive_reads_(0),
read_threshold_(1024), read_threshold_(1024),
collected_(0), collected_(0),
max_(1024), max_(1024),
rd_flag_(net::receive_policy_flag::exactly), rd_flag_(net::receive_policy_flag::exactly),
written_(0) { written_(0) {
// nop // nop
} }
...@@ -80,8 +79,9 @@ public: ...@@ -80,8 +79,9 @@ public:
} }
CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(rres)); CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(rres));
auto result = (get<size_t>(rres) > 0) ? auto result = (get<size_t>(rres) > 0)
static_cast<size_t>(get<size_t>(rres)) : 0; ? static_cast<size_t>(get<size_t>(rres))
: 0;
collected_ += result; collected_ += result;
if (collected_ >= read_threshold_) { if (collected_ >= read_threshold_) {
parent.application().process(read_buf_, *this, parent); parent.application().process(read_buf_, *this, parent);
...@@ -94,20 +94,13 @@ public: ...@@ -94,20 +94,13 @@ public:
template <class Parent> template <class Parent>
bool handle_write_event(Parent& parent) { bool handle_write_event(Parent& parent) {
while(write_some(parent)); // write while write_buf not empty for (auto msg = parent.next_message(); msg != nullptr; msg = parent.next_message()) {
parent.application().prepare(std::move(msg), *this);
// check new messages in parents message_queue
std::unique_ptr<caf::net::endpoint_manager::message> msg;
while ((msg = parent.next_message())) {
parent.application().prepare(std::move(msg), *this, parent);
} }
// write prepared data
return write_some(parent);
}
template <class Parent> // write prepared data
bool write_some(Parent& parent) { if (write_buf_.empty())
if (write_buf_.empty()) return false; return false;
auto len = write_buf_.size() - written_; auto len = write_buf_.size() - written_;
void* buf = write_buf_.data() + written_; void* buf = write_buf_.data() + written_;
CAF_LOG_TRACE(CAF_ARG(handle_.id) << CAF_ARG(len)); CAF_LOG_TRACE(CAF_ARG(handle_.id) << CAF_ARG(len));
...@@ -117,9 +110,11 @@ public: ...@@ -117,9 +110,11 @@ public:
handle_error(parent, get<caf::sec>(sres)); handle_error(parent, get<caf::sec>(sres));
return false; return false;
} }
CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(sres)); CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id)
auto result = (get<size_t>(sres) > 0) ? << CAF_ARG(sres));
static_cast<size_t>(get<size_t>(sres)) : 0; auto result = (get<size_t>(sres) > 0)
? static_cast<size_t>(get<size_t>(sres))
: 0;
// update state // update state
written_ += result; written_ += result;
...@@ -128,13 +123,13 @@ public: ...@@ -128,13 +123,13 @@ public:
write_buf_.clear(); write_buf_.clear();
return false; return false;
} else { } else {
return true; return true;
} }
} }
template <class Parent> template <class Parent>
void resolve(Parent& parent, const std::string& path, actor listener) { void resolve(Parent& parent, const std::string& path, actor listener) {
parent.application().resolve(*this, path, listener); parent.application().resolve(parent, path, listener);
// TODO should parent be passed as well? // TODO should parent be passed as well?
} }
...@@ -168,6 +163,5 @@ private: ...@@ -168,6 +163,5 @@ private:
size_t written_; size_t written_;
}; };
} // namespace policy } // namespace policy
} // namespace caf } // namespace caf
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* http://www.boost.org/LICENSE_1_0.txt. * * http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/ ******************************************************************************/
#include "caf/policy/scribe_policy.hpp" #include "caf/policy/scribe.hpp"
#include <system_error> #include <system_error>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
namespace caf { namespace caf {
namespace policy { namespace policy {
void scribe_policy::prepare_next_read() { void scribe::prepare_next_read() {
collected_ = 0; collected_ = 0;
// This cast does nothing, but prevents a weird compiler error on GCC <= 4.9. // This cast does nothing, but prevents a weird compiler error on GCC <= 4.9.
// TODO: remove cast when dropping support for GCC 4.9. // TODO: remove cast when dropping support for GCC 4.9.
...@@ -52,13 +52,13 @@ void scribe_policy::prepare_next_read() { ...@@ -52,13 +52,13 @@ void scribe_policy::prepare_next_read() {
} }
} }
void scribe_policy::configure_read(net::receive_policy::config cfg) { void scribe::configure_read(net::receive_policy::config cfg) {
rd_flag_ = cfg.first; rd_flag_ = cfg.first;
max_ = cfg.second; max_ = cfg.second;
prepare_next_read(); prepare_next_read();
} }
std::vector<char>& scribe_policy::wr_buf() { std::vector<char>& scribe::wr_buf() {
return write_buf_; return write_buf_;
} }
......
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