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

Method read_header

lib_acl_cpp/src/mqtt/mqtt_client.cpp:103–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103bool mqtt_client::read_header(mqtt_header& header) {
104 char ch;
105 if (!conn_->read(ch)) {
106 //logger_error("read header type error: %s", last_serror());
107 return false;
108 }
109
110 // update the first char for mqtt_type_t
111 if (header.update(&ch, 1) != 0) {
112 logger_debug(DEBUG_MQTT, 1, "invalid header type=%d", (int) ch);
113 return false;
114 }
115
116 for (int i = 0; i < 4; i++) {
117 if (!conn_->read(ch)) {
118 logger_debug(DEBUG_MQTT, 1, "read char error: %s, i=%d",
119 last_serror(), i);
120 return false;
121 }
122 if (header.update(&ch, 1) != 0) {
123 logger_debug(DEBUG_MQTT, 1, "header_update error, ch=%d",
124 (int) ch);
125 return false;
126 }
127 if (header.finished()) {
128 break;
129 }
130 }
131
132 if (!header.finished()) {
133 logger_debug(DEBUG_MQTT, 1, "get mqtt header error");
134 return false;
135 }
136
137 return true;
138}
139
140bool mqtt_client::read_message(const mqtt_header& header, mqtt_message& body) {
141 unsigned len = header.get_remaining_length();

Callers 7

handle_requestFunction · 0.45
on_acceptMethod · 0.45
thread_on_readMethod · 0.45
thread_on_readMethod · 0.45
handle_connMethod · 0.45
handle_connMethod · 0.45
read_requestMethod · 0.45

Calls 3

last_serrorFunction · 0.50
readMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected