MCPcopy Create free account
hub / github.com/acl-dev/acl / read_message

Method read_message

lib_acl_cpp/src/mqtt/mqtt_client.cpp:140–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140bool mqtt_client::read_message(const mqtt_header& header, mqtt_message& body) {
141 unsigned len = header.get_remaining_length();
142 if (len == 0) {
143 return true;
144 }
145
146 char buf[8192];
147 while (len > 0) {
148 size_t size = sizeof(buf) > len ? len : sizeof(buf);
149 int n = conn_->read(buf, size);
150 if (n == -1) {
151 logger_debug(DEBUG_MQTT, 1, "read body error: %s",
152 last_serror());
153 return false;
154 }
155
156 len -= n;
157
158 n = body.update(buf, (int) n);
159 if (n == -1) {
160 logger_debug(DEBUG_MQTT, 1, "update body error");
161 return false;
162 } else if (n != 0) {
163 logger_debug(DEBUG_MQTT, 1, "invalid body data");
164 return false;
165 }
166 }
167
168 if (!body.finished()) {
169 logger_debug(DEBUG_MQTT, 1, "body not finished!");
170 return false;
171 }
172 return true;
173}
174
175} // namespace acl

Callers

nothing calls this directly

Calls 3

last_serrorFunction · 0.50
readMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected