Commit 3c2a2f88 authored by Joseph Noir's avatar Joseph Noir

Fix receive buffer size after autoconnect

parent 328abb98
...@@ -59,8 +59,13 @@ behavior datagram_connection_broker(broker* self, ...@@ -59,8 +59,13 @@ behavior datagram_connection_broker(broker* self,
return { return {
[=](new_datagram_msg& msg) { [=](new_datagram_msg& msg) {
auto hdl = msg.handle; auto hdl = msg.handle;
auto cap = msg.buf.capacity();
self->send(system_broker, std::move(msg), self->take(hdl), port); self->send(system_broker, std::move(msg), self->take(hdl), port);
self->quit(); self->quit();
// The buffer returned to the multiplexer will have capacity zero
// if we don't do this. Handling this case here is cheaper than
// checking before each receive in the multiplexer.
msg.buf.reserve(cap);
}, },
after(autoconnect_timeout) >> [=]() { after(autoconnect_timeout) >> [=]() {
CAF_LOG_TRACE(CAF_ARG("")); CAF_LOG_TRACE(CAF_ARG(""));
......
...@@ -908,7 +908,7 @@ bool test_multiplexer::try_read_data(datagram_handle hdl) { ...@@ -908,7 +908,7 @@ bool test_multiplexer::try_read_data(datagram_handle hdl) {
auto& from = rh.vn_buf.front(); auto& from = rh.vn_buf.front();
auto& to = data->rd_buf; auto& to = data->rd_buf;
to.first = from.first; to.first = from.first;
CAF_ASSERT(to.second.capacity() > from.second.size()); CAF_ASSERT(to.second.capacity() >= from.second.size());
to.second.resize(from.second.size()); to.second.resize(from.second.size());
std::copy(from.second.begin(), from.second.end(), to.second.begin()); std::copy(from.second.begin(), from.second.end(), to.second.begin());
rh.vn_buf.pop_front(); rh.vn_buf.pop_front();
......
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