Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nall: correctly handle TCP peer disconnections in tcp-socket.cpp #1365

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nall/gdb/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ namespace nall::GDB {

if(requestDisconnect) {
requestDisconnect = false;
printf("GDB ending session, disconnecting client\n");
if(!noAckMode) {
sendText("+");
}
Expand Down Expand Up @@ -500,11 +499,13 @@ namespace nall::GDB {
}

auto Server::onConnect() -> void {
printf("GDB client connected\n");
resetClientData();
hasActiveClient = true;
}

auto Server::onDisconnect() -> void {
printf("GDB client disconnected\n");
hadHandshake = false;
resetClientData();
}
Expand Down
9 changes: 8 additions & 1 deletion nall/tcptext/tcp-socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ NALL_HEADER_INLINE auto Socket::open(u32 port, bool useIPv4) -> bool {

while(!stopServer)
{
if(fdClient < 0) {
if(fdClient < 0 || wantKickClient) {
std::this_thread::sleep_for(std::chrono::milliseconds(CLIENT_SLEEP_MS));
continue;
}
Expand All @@ -228,6 +228,13 @@ NALL_HEADER_INLINE auto Socket::open(u32 port, bool useIPv4) -> bool {
if constexpr(TCP_LOG_MESSAGES) {
printf("%.4f | TCP <: [%d]: %.*s ([%d]: %.*s)\n", (f64)chrono::millisecond() / 1000.0, length, length, (char*)receiveBuffer.data(), length, length, (char*)packet);
}
} else if(length == 0) {
disconnectClient();
} else {
if (errno != EAGAIN) {
printf("TCP server: error receiving data from client: %s\n", strerror(errno));
disconnectClient();
}
}
}
});
Expand Down
Loading