Reimplemented disconnection based on stalls. If we stall for 10 seconds,

disconnect.
This commit is contained in:
Gregor Richards 2016-09-13 17:33:26 -04:00
parent 8aa48cd3f9
commit 6829b80c6b
3 changed files with 25 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include <retro_assert.h>
#include <net/net_compat.h>
#include <net/net_socket.h>
#include <features/features_cpu.h>
#include <retro_endianness.h>
#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;

View File

@ -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)

View File

@ -20,6 +20,7 @@
#include "netplay.h"
#include <net/net_compat.h>
#include <features/features_cpu.h>
#include <retro_endianness.h>
#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;
};