Skip to content

Commit

Permalink
call on_disconnect in more situations so we can properly handle dead …
Browse files Browse the repository at this point in the history
…sockets
  • Loading branch information
braindigitalis committed Dec 10, 2024
1 parent f3b85a4 commit 6e87030
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/dpp/discordclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ discord_client::~discord_client()
void discord_client::on_disconnect()
{
set_resume_hostname();
log(dpp::ll_debug, "Lost connection to websocket on shard " + std::to_string(shard_id) + ", reconnecting...");
if (sfd != INVALID_SOCKET) {
log(dpp::ll_debug, "Lost connection to websocket on shard " + std::to_string(shard_id) + ", reconnecting...");
}
ssl_client::close();
owner->add_reconnect(this->shard_id);
}
Expand Down
10 changes: 4 additions & 6 deletions src/dpp/wsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ void websocket_client::one_second_timer()
/* Handle timeouts for connect(), SSL negotiation and HTTP negotiation */
if (!timed_out && sfd != INVALID_SOCKET) {
if (!tcp_connect_done && now >= timeout) {
log(ll_warning, "Websocket connection timed out: connect()");
log(ll_trace, "Websocket connection timed out: connect()");
timed_out = true;
this->close();
} else if (tcp_connect_done && !connected && now >= timeout && this->state != CONNECTED) {
log(ll_warning, "Websocket connection timed out: SSL handshake");
log(ll_trace, "Websocket connection timed out: SSL handshake");
timed_out = true;
this->close();
} else if (now >= timeout && this->state != CONNECTED) {
log(ll_warning, "Websocket connection timed out: HTTP negotiation");
log(ll_trace, "Websocket connection timed out: HTTP negotiation");
timed_out = true;
this->close();
}
Expand Down Expand Up @@ -370,9 +370,7 @@ void websocket_client::on_disconnect()

void websocket_client::close()
{
if (sfd != INVALID_SOCKET) {
this->on_disconnect();
}
this->on_disconnect();
this->state = HTTP_HEADERS;
ssl_client::close();
}
Expand Down

0 comments on commit 6e87030

Please sign in to comment.