Commit 1c3f96ad authored by Jakob Otto's avatar Jakob Otto

Cleanup for PR

parent 81a80237
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#ifdef CAF_WINDOWS #ifdef CAF_WINDOWS
# include <winsock2.h> # include <winsock2.h>
#else #else
# include <caf/actor.hpp> # include <caf/actor.hpp>
# include <sys/socket.h> # include <sys/socket.h>
# include <sys/types.h> # include <sys/types.h>
...@@ -61,7 +62,7 @@ public: ...@@ -61,7 +62,7 @@ public:
template <class Parent> template <class Parent>
error init(Parent& parent) { error init(Parent& parent) {
prepare_next_read(); prepare_next_read();
parent.mask_add(net::operation::read_write); parent.mask_add(net::operation::read);
return none; return none;
} }
...@@ -70,19 +71,10 @@ public: ...@@ -70,19 +71,10 @@ public:
void* buf = read_buf_.data() + collected_; void* buf = read_buf_.data() + collected_;
size_t len = read_threshold_ - collected_; size_t len = read_threshold_ - collected_;
CAF_LOG_TRACE(CAF_ARG(handle_.id) << CAF_ARG(len)); CAF_LOG_TRACE(CAF_ARG(handle_.id) << CAF_ARG(len));
auto rres = read(handle_, buf, len); variant<size_t, sec> ret = read(handle_, buf, len);
if (rres.is<caf::sec>()) { if (auto num_bytes = get_if<size_t>(&ret)) {
// Make sure WSAGetLastError gets called immediately on Windows. CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(*num_bytes));
CAF_LOG_DEBUG("receive failed" << CAF_ARG(get<sec>(rres))); collected_ += *num_bytes;
handle_error(parent, get<caf::sec>(rres));
return false;
}
CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(rres));
auto result = (get<size_t>(rres) > 0)
? static_cast<size_t>(get<size_t>(rres))
: 0;
collected_ += result;
if (collected_ >= read_threshold_) { if (collected_ >= read_threshold_) {
parent.application().process(read_buf_, *this, parent); parent.application().process(read_buf_, *this, parent);
prepare_next_read(); prepare_next_read();
...@@ -90,6 +82,13 @@ public: ...@@ -90,6 +82,13 @@ public:
} else { } else {
return true; return true;
} }
} else {
// Make sure WSAGetLastError gets called immediately on Windows.
auto err = get<sec>(ret);
CAF_LOG_DEBUG("receive failed" << CAF_ARG(err));
handle_error(parent, err);
return false;
}
} }
template <class Parent> template <class Parent>
...@@ -107,25 +106,16 @@ public: ...@@ -107,25 +106,16 @@ public:
template <class Parent> template <class Parent>
bool write_some(Parent& parent) { bool write_some(Parent& parent) {
// write prepared data
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));
auto sres = net::write(handle_, buf, len); auto ret = net::write(handle_, buf, len);
if (sres.is<caf::sec>()) { if (auto num_bytes = get_if<size_t>(&ret)) {
CAF_LOG_ERROR("send failed"); CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(*num_bytes));
handle_error(parent, get<caf::sec>(sres));
return false;
}
CAF_LOG_DEBUG(CAF_ARG(len) << CAF_ARG(handle_.id) << CAF_ARG(sres));
auto result = (get<size_t>(sres) > 0)
? static_cast<size_t>(get<size_t>(sres))
: 0;
// update state // update state
written_ += result; written_ += *num_bytes;
if (written_ >= write_buf_.size()) { if (written_ >= write_buf_.size()) {
written_ = 0; written_ = 0;
write_buf_.clear(); write_buf_.clear();
...@@ -133,6 +123,11 @@ public: ...@@ -133,6 +123,11 @@ public:
} else { } else {
return true; return true;
} }
} else {
CAF_LOG_ERROR("send failed");
handle_error(parent, get<sec>(ret));
return false;
}
} }
template <class Parent> template <class Parent>
......
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
// nop // nop
} }
void handle_error(caf::sec) { void handle_error(sec) {
// nop // nop
} }
......
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