Skip to content
Snippets Groups Projects
Commit 4e11e8cd authored by Adrien Béraud's avatar Adrien Béraud
Browse files

mxsock: oneShot

Change-Id: Icf205d732f7eb419d59b1de31389a715ddb5b7e1
parent 86b7e653
Branches
No related tags found
No related merge requests found
......@@ -462,12 +462,14 @@ MultiplexedSocket::write(const uint16_t& channel,
ec = std::make_error_code(std::errc::message_size);
return -1;
}
msgpack::sbuffer buffer(len + 16);
bool oneShot = len < 8192;
msgpack::sbuffer buffer(oneShot ? 16 + len : 16);
msgpack::packer<msgpack::sbuffer> pk(&buffer);
pk.pack_array(2);
pk.pack(channel);
pk.pack_bin(len);
pk.pack_bin_body((const char*) buf, len);
if (oneShot)
pk.pack_bin_body((const char*) buf, len);
std::unique_lock<std::mutex> lk(pimpl_->writeMtx);
if (!pimpl_->endpoint) {
......@@ -476,6 +478,8 @@ MultiplexedSocket::write(const uint16_t& channel,
return -1;
}
int res = pimpl_->endpoint->write((const unsigned char*) buffer.data(), buffer.size(), ec);
if (not oneShot and res >= 0)
res = pimpl_->endpoint->write(buf, len, ec);
lk.unlock();
if (res < 0) {
if (ec)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment