MCPcopy Create free account
hub / github.com/dermesser/libsocket / rcvmsg

Method rcvmsg

C++/dgramoverstream.cpp:81–110  ·  view source on GitHub ↗

* @brief Receive a message and place it into dst. * * No more than dst.size() bytes will be received and placed into dst. */

Source from the content-addressed store, hash-verified

79 * No more than dst.size() bytes will be received and placed into dst.
80 */
81ssize_t dgram_over_stream::rcvmsg(std::string* dst) {
82 uint32_t expected = receive_header();
83
84 if (expected <= dst->size()) dst->resize(expected);
85
86 size_t to_receive = dst->size();
87 size_t received = 0;
88
89 while (received < to_receive) {
90 ssize_t result = receive_bytes(to_receive - received);
91
92 if (result < 0)
93 throw socket_exception(
94 __FILE__, __LINE__,
95 "dgram_over_stream::rcvmsg(): Could not receive message!",
96 false);
97
98 dst->replace(received, result, RECV_BUF);
99
100 received += (size_t)result;
101 }
102
103 // Consume remaining frame that doesn't fit into dst.
104 ssize_t rest = expected - to_receive;
105 while (rest > 0) {
106 rest -= receive_bytes(rest);
107 }
108
109 return received;
110}
111
112/**
113 * @brief Send the message `msg` as one frame.

Callers 4

run_clientFunction · 0.80
run_string_clientFunction · 0.80
run_vec_clientFunction · 0.80
run_serverFunction · 0.80

Calls 1

socket_exceptionClass · 0.85

Tested by

no test coverage detected