Skip to content

Commit

Permalink
fix(QWebsocketpp): add more exception handling
Browse files Browse the repository at this point in the history
Signed-off-by: Yibai Zhang <xm1994@gmail.com>
  • Loading branch information
summershrimp committed Jan 9, 2024
1 parent 8d5ff53 commit 84021e0
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/util/QWebsocketpp/QWebsocketpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,19 @@ qint64 QWebsocketpp::sendBinaryMessage(const QByteArray &data)
if (!running) {
return 0;
}

if (client_is_tls) {
wss_client->send(hdl, data.toStdString(),
websocketpp::frame::opcode::binary);
} else {
ws_client->send(hdl, data.toStdString(),
websocketpp::frame::opcode::binary);
try {
if (client_is_tls) {
wss_client->send(hdl, data.toStdString(),
websocketpp::frame::opcode::binary);
} else {
ws_client->send(hdl, data.toStdString(),
websocketpp::frame::opcode::binary);
}
return data.size();
} catch (websocketpp::exception const &e) {
std::cout << e.what();
return 0;
}
return data.size();
}

qint64 QWebsocketpp::sendTextMessage(const QString &message)
Expand All @@ -266,14 +270,19 @@ qint64 QWebsocketpp::sendTextMessage(const QString &message)
if (!running) {
return 0;
}
if (client_is_tls) {
wss_client->send(hdl, message.toStdString(),
websocketpp::frame::opcode::text);
} else {
ws_client->send(hdl, message.toStdString(),
websocketpp::frame::opcode::text);
try {
if (client_is_tls) {
wss_client->send(hdl, message.toStdString(),
websocketpp::frame::opcode::text);
} else {
ws_client->send(hdl, message.toStdString(),
websocketpp::frame::opcode::text);
}
return message.size();
} catch (websocketpp::exception const &e) {
std::cout << e.what();
return 0;
}
return message.size();
}

QString QWebsocketpp::errorString() const
Expand Down

0 comments on commit 84021e0

Please sign in to comment.