From 37ca5e562b25192952ced2edf3036e8676ba32ae Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 21 Feb 2010 09:50:30 +0000 Subject: [PATCH] Fix network disconnect and handle send failures --- Src/C64_SDL.h | 2 ++ Src/Network.cpp | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index ed2aa73..fb0b7c3 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -162,6 +162,8 @@ void C64::network_vblank() remote->Disconnect(); delete remote; this->network = NULL; + TheC64->network_connection_type = NONE; + return; } diff --git a/Src/Network.cpp b/Src/Network.cpp index 2896613..fc61002 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -597,7 +597,7 @@ bool Network::SendUpdate(struct sockaddr_in *addr) v = this->SendTo((void*)p, this->sock, size_to_send, addr); - if (v < 0 || (size_t)v != size_to_send) + if (v <= 0 || (size_t)v != size_to_send) return false; cur_sz += size_to_send; p += size_to_send; @@ -734,6 +734,12 @@ bool Network::MarshalAllData(NetworkUpdate *ud) { NetworkUpdate *p = ud; + /* Already marshalled? */ + if (ntohs(p->magic) == FRODO_NETWORK_MAGIC) { + warning("Data already marshalled\n"); + return true; + } + while (p->type != STOP) { NetworkUpdate *nxt = this->GetNext(p); @@ -992,8 +998,9 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst) /* We won't receive this, but it also doesn't really matter */ break; case DISCONNECT: - out = false; - break; + printf("Got disconnect\n"); + TheC64->network_connection_type = NONE; + return false; default: break; } @@ -1290,19 +1297,20 @@ network_connection_error_t Network::WaitForBandWidthReply() void Network::Disconnect() { - this->ResetNetworkUpdate(); + printf("Disconnecting\n"); + this->ResetNetworkUpdate(); NetworkUpdate *disconnect = InitNetworkUpdate(this->cur_ud, DISCONNECT, sizeof(NetworkUpdate)); /* Add a stop at the end of the update */ this->AddNetworkUpdate(disconnect); - this->SendServerUpdate(); - this->SendPeerUpdate(); - TheC64->network_connection_type = NONE; + this->SendPeerUpdate(); + this->SendServerUpdate(); } + bool Network::networking_started = false; #if defined(GEKKO)