| 101 | } |
| 102 | |
| 103 | bool 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 | |
| 140 | bool mqtt_client::read_message(const mqtt_header& header, mqtt_message& body) { |
| 141 | unsigned len = header.get_remaining_length(); |
no test coverage detected