| 185 | } |
| 186 | |
| 187 | void WebSocketClient::sendClose(int status, QString reason) |
| 188 | { |
| 189 | Debug(_log, "send close: %d %s", status, QSTRING_CSTR(reason)); |
| 190 | ErrorIf(!reason.isEmpty(), _log, QSTRING_CSTR(reason)); |
| 191 | _receiveBuffer.clear(); |
| 192 | QByteArray sendBuffer; |
| 193 | |
| 194 | sendBuffer.append(136 + (status - 1000)); |
| 195 | int length = reason.size(); |
| 196 | if (length >= 126) |
| 197 | { |
| 198 | sendBuffer.append((length > 0xffff) ? 127 : 126); |
| 199 | int num_bytes = (length > 0xffff) ? 8 : 2; |
| 200 | |
| 201 | for (int c = num_bytes - 1; c != -1; c--) |
| 202 | { |
| 203 | sendBuffer.append(quint8((static_cast<unsigned long long>(length) >> (8 * c)) % 256)); |
| 204 | } |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | sendBuffer.append(quint8(length)); |
| 209 | } |
| 210 | |
| 211 | sendBuffer.append(reason.toUtf8()); |
| 212 | |
| 213 | _socket->write(sendBuffer); |
| 214 | _socket->flush(); |
| 215 | _socket->close(); |
| 216 | } |
| 217 | |
| 218 | qint64 WebSocketClient::sendMessage(const QJsonObject& obj) |
| 219 | { |