mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
A more sophisticated status variable for later making the initial
connection nonblocking.
This commit is contained in:
parent
0f5eec9987
commit
ba76528b8f
@ -281,7 +281,7 @@ static void hangup(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay)
|
||||
return;
|
||||
if (!netplay->has_connection)
|
||||
if (netplay->status == RARCH_NETPLAY_CONNECTION_NONE)
|
||||
return;
|
||||
|
||||
RARCH_WARN("Netplay has disconnected. Will continue without connection ...\n");
|
||||
@ -300,7 +300,7 @@ static void hangup(netplay_t *netplay)
|
||||
}
|
||||
}
|
||||
|
||||
netplay->has_connection = false;
|
||||
netplay->status = RARCH_NETPLAY_CONNECTION_NONE;
|
||||
|
||||
/* Reset things that will behave oddly if we get a new connection */
|
||||
netplay->remote_paused = false;
|
||||
@ -328,7 +328,7 @@ static bool netplay_should_skip(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay)
|
||||
return false;
|
||||
return netplay->is_replay && netplay->has_connection;
|
||||
return netplay->is_replay && (netplay->status == RARCH_NETPLAY_CONNECTION_PLAYING);
|
||||
}
|
||||
|
||||
static bool netplay_can_poll(netplay_t *netplay)
|
||||
@ -907,7 +907,7 @@ static bool netplay_poll(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (!netplay_data->has_connection)
|
||||
if (netplay_data->status == RARCH_NETPLAY_CONNECTION_NONE)
|
||||
return false;
|
||||
|
||||
netplay_data->can_poll = false;
|
||||
@ -1009,7 +1009,7 @@ static bool netplay_is_alive(void)
|
||||
{
|
||||
if (!netplay_data)
|
||||
return false;
|
||||
return netplay_data->has_connection;
|
||||
return (netplay_data->status == RARCH_NETPLAY_CONNECTION_PLAYING);
|
||||
}
|
||||
|
||||
static bool netplay_flip_port(netplay_t *netplay, bool port)
|
||||
@ -1588,7 +1588,7 @@ bool netplay_pre_frame(netplay_t *netplay)
|
||||
if (!netplay->net_cbs->pre_frame(netplay))
|
||||
return false;
|
||||
|
||||
return (!netplay->has_connection ||
|
||||
return ((netplay->status != RARCH_NETPLAY_CONNECTION_PLAYING) ||
|
||||
(!netplay->stall && !netplay->remote_paused));
|
||||
}
|
||||
|
||||
@ -1622,7 +1622,8 @@ void netplay_frontend_paused(netplay_t *netplay, bool paused)
|
||||
return;
|
||||
|
||||
netplay->local_paused = paused;
|
||||
if (netplay->has_connection && !netplay->spectate.enabled)
|
||||
if (netplay->status != RARCH_NETPLAY_CONNECTION_NONE &&
|
||||
!netplay->spectate.enabled)
|
||||
{
|
||||
netplay_send_raw_cmd(netplay, paused
|
||||
? NETPLAY_CMD_PAUSE : NETPLAY_CMD_RESUME, NULL, 0);
|
||||
@ -1649,7 +1650,7 @@ void netplay_load_savestate(netplay_t *netplay,
|
||||
retro_ctx_serialize_info_t tmp_serial_info;
|
||||
uint32_t rd, wn;
|
||||
|
||||
if (!netplay->has_connection)
|
||||
if (netplay->status != RARCH_NETPLAY_CONNECTION_PLAYING)
|
||||
return;
|
||||
|
||||
/* Record it in our own buffer */
|
||||
@ -1745,7 +1746,7 @@ void netplay_load_savestate(netplay_t *netplay,
|
||||
**/
|
||||
bool netplay_disconnect(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay || !netplay->has_connection)
|
||||
if (!netplay || (netplay->status == RARCH_NETPLAY_CONNECTION_NONE))
|
||||
return true;
|
||||
hangup(netplay);
|
||||
return true;
|
||||
|
@ -105,13 +105,13 @@ static bool netplay_net_pre_frame(netplay_t *netplay)
|
||||
}
|
||||
|
||||
/* If we can't transmit savestates, we must stall until the client is ready */
|
||||
if (!netplay->has_connection &&
|
||||
if (netplay->status != RARCH_NETPLAY_CONNECTION_PLAYING &&
|
||||
netplay->self_frame_count > 0 &&
|
||||
(netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION)))
|
||||
netplay->stall = RARCH_NETPLAY_STALL_NO_CONNECTION;
|
||||
}
|
||||
|
||||
if (netplay->is_server && !netplay->has_connection)
|
||||
if (netplay->is_server && netplay->status == RARCH_NETPLAY_CONNECTION_NONE)
|
||||
{
|
||||
fd_set fds;
|
||||
struct timeval tmp_tv = {0};
|
||||
@ -163,7 +163,7 @@ static bool netplay_net_pre_frame(netplay_t *netplay)
|
||||
/* Establish the connection */
|
||||
if (netplay_handshake(netplay))
|
||||
{
|
||||
netplay->has_connection = true;
|
||||
netplay->status = RARCH_NETPLAY_CONNECTION_PLAYING;
|
||||
|
||||
/* FIXME: Not the best place for this, needs to happen after initial
|
||||
* connection in get_info */
|
||||
@ -223,7 +223,7 @@ static void netplay_net_post_frame(netplay_t *netplay)
|
||||
netplay->self_frame_count++;
|
||||
|
||||
/* Only relevant if we're connected */
|
||||
if (!netplay->has_connection)
|
||||
if (netplay->status != RARCH_NETPLAY_CONNECTION_PLAYING)
|
||||
{
|
||||
netplay->read_frame_count = netplay->other_frame_count = netplay->self_frame_count;
|
||||
netplay->read_ptr = netplay->other_ptr = netplay->self_ptr;
|
||||
@ -353,7 +353,7 @@ static bool netplay_net_info_cb(netplay_t* netplay, unsigned frames)
|
||||
{
|
||||
if (!netplay_handshake(netplay))
|
||||
return false;
|
||||
netplay->has_connection = true;
|
||||
netplay->status = RARCH_NETPLAY_CONNECTION_PLAYING;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -117,11 +117,20 @@ struct netplay_callbacks {
|
||||
bool (*info_cb) (netplay_t *netplay, unsigned frames);
|
||||
};
|
||||
|
||||
enum rarch_netplay_connection_status
|
||||
{
|
||||
RARCH_NETPLAY_CONNECTION_NONE = 0,
|
||||
RARCH_NETPLAY_CONNECTION_INIT, /* Waiting for header */
|
||||
RARCH_NETPLAY_CONNECTION_PRE_NICK, /* Waiting for nick */
|
||||
RARCH_NETPLAY_CONNECTION_PRE_SRAM, /* Waiting for SRAM */
|
||||
RARCH_NETPLAY_CONNECTION_PLAYING /* Normal ready state */
|
||||
};
|
||||
|
||||
enum rarch_netplay_stall_reasons
|
||||
{
|
||||
RARCH_NETPLAY_STALL_NONE = 0,
|
||||
RARCH_NETPLAY_STALL_RUNNING_FAST,
|
||||
RARCH_NETPLAY_STALL_NO_CONNECTION
|
||||
RARCH_NETPLAY_STALL_NONE = 0,
|
||||
RARCH_NETPLAY_STALL_RUNNING_FAST,
|
||||
RARCH_NETPLAY_STALL_NO_CONNECTION
|
||||
};
|
||||
|
||||
struct netplay
|
||||
@ -130,6 +139,9 @@ struct netplay
|
||||
char other_nick[32];
|
||||
struct sockaddr_storage other_addr;
|
||||
|
||||
/* Status of our connection */
|
||||
enum rarch_netplay_connection_status status;
|
||||
|
||||
struct retro_callbacks cbs;
|
||||
/* TCP connection for state sending, etc. Also used for commands */
|
||||
int fd;
|
||||
@ -140,7 +152,6 @@ struct netplay
|
||||
struct natt_status nat_traversal_state;
|
||||
/* Which port is governed by netplay (other user)? */
|
||||
unsigned port;
|
||||
bool has_connection;
|
||||
|
||||
struct delta_frame *buffer;
|
||||
size_t buffer_size;
|
||||
|
@ -285,7 +285,7 @@ static bool netplay_spectate_info_cb(netplay_t* netplay, unsigned frames)
|
||||
return false;
|
||||
}
|
||||
|
||||
netplay->has_connection = true;
|
||||
netplay->status = RARCH_NETPLAY_CONNECTION_PLAYING;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user