| 138 | } |
| 139 | |
| 140 | bool 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 |
nothing calls this directly
no test coverage detected