From 6829b80c6bb1ff530658d40d187ac533421a11de Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Tue, 13 Sep 2016 17:33:26 -0400 Subject: [PATCH] Reimplemented disconnection based on stalls. If we stall for 10 seconds, disconnect. --- network/netplay/netplay.c | 19 +++++++++++++++++++ network/netplay/netplay_net.c | 4 ++++ network/netplay/netplay_private.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/network/netplay/netplay.c b/network/netplay/netplay.c index 0cf6653012..ef72732002 100644 --- a/network/netplay/netplay.c +++ b/network/netplay/netplay.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "netplay_private.h" @@ -408,6 +409,8 @@ static void simulate_input(netplay_t *netplay) netplay->buffer[ptr].used_real = false; } +#define MAX_STALL_TIME_USEC 10000000 + /** * netplay_poll: * @netplay : pointer to netplay object @@ -451,7 +454,23 @@ static bool netplay_poll(netplay_t *netplay) default: /* not stalling */ if (netplay->read_frame_count + netplay->stall_frames <= netplay->self_frame_count) + { netplay->stall = RARCH_NETPLAY_STALL_RUNNING_FAST; + netplay->stall_time = cpu_features_get_time_usec(); + } + } + + /* If we're stalling, consider disconnection */ + if (netplay->stall) + { + retro_time_t now = cpu_features_get_time_usec(); + if (now - netplay->stall_time >= MAX_STALL_TIME_USEC) + { + /* Stalled out! */ + netplay->has_connection = false; + warn_hangup(); + return false; + } } return true; diff --git a/network/netplay/netplay_net.c b/network/netplay/netplay_net.c index ea15cac265..6458f1e412 100644 --- a/network/netplay/netplay_net.c +++ b/network/netplay/netplay_net.c @@ -64,6 +64,10 @@ static void netplay_net_post_frame(netplay_t *netplay) { netplay->self_frame_count++; + /* Only relevant if we're connected */ + if (!netplay->has_connection) + return; + /* Skip ahead if we predicted correctly. * Skip until our simulation failed. */ while (netplay->other_frame_count < netplay->read_frame_count) diff --git a/network/netplay/netplay_private.h b/network/netplay/netplay_private.h index 7785195cb9..e8bf820e40 100644 --- a/network/netplay/netplay_private.h +++ b/network/netplay/netplay_private.h @@ -20,6 +20,7 @@ #include "netplay.h" #include +#include #include #include "../../core.h" @@ -144,6 +145,7 @@ struct netplay /* And stalling */ uint32_t stall_frames; int stall; + retro_time_t stall_time; struct netplay_callbacks* net_cbs; };