Added bson support for user message protocol. (#99)

This commit is contained in:
Ravin Perera
2020-07-02 21:40:55 +05:30
committed by GitHub
parent 8103ef7af6
commit 96f23cb0ff
47 changed files with 1424 additions and 810 deletions

View File

@@ -71,6 +71,13 @@ namespace comm
}
else if (read_len > 0)
{
if (!is_binary)
{
read_buffer.resize(read_len);
if (read(read_fd, read_buffer.data(), read_len) < read_len)
return -1;
}
int res = on_message(std::string_view(read_buffer.data(), read_len));
read_buffer.clear(); // Clear the buffer after read operation.
read_buffer_filled_size = 0;
@@ -91,6 +98,12 @@ namespace comm
return peer_sess_handler.on_message(*this, message);
}
int comm_session::send(const std::vector<uint8_t> &message) const
{
std::string_view sv(reinterpret_cast<const char *>(message.data()), message.size());
send(sv);
}
int comm_session::send(std::string_view message) const
{
if (state == SESSION_STATE::CLOSED)