MCPcopy Create free account
hub / github.com/awawa-dev/HyperHDR / sendClose

Method sendClose

sources/webserver/WebSocketClient.cpp:187–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187void 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
218qint64 WebSocketClient::sendMessage(const QJsonObject& obj)
219{

Callers 1

WebSocketClientMethod · 0.95

Calls 5

isEmptyMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected