Fix race condition in NAT traversal task.

This commit is contained in:
Gregor Richards 2017-02-20 20:16:53 -05:00
parent ef5b8046f0
commit 972b41f803
3 changed files with 6 additions and 1 deletions

View File

@ -685,6 +685,7 @@ bool netplay_pre_frame(netplay_t *netplay)
/* NAT traversal if applicable */
if (netplay->nat_traversal &&
!netplay->nat_traversal_task_oustanding &&
netplay->nat_traversal_state.request_outstanding &&
!netplay->nat_traversal_state.have_inet4)
{
@ -1198,7 +1199,10 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
ret = netplay_disconnect(netplay_data);
goto done;
case RARCH_NETPLAY_CTL_FINISHED_NAT_TRAVERSAL:
netplay_data->nat_traversal_task_oustanding = false;
#ifndef HAVE_SOCKET_LEGACY
netplay_announce_nat_traversal(netplay_data);
#endif
goto done;
default:
case RARCH_NETPLAY_CTL_NONE:

View File

@ -1432,5 +1432,6 @@ void netplay_announce_nat_traversal(netplay_t *netplay)
void netplay_init_nat_traversal(netplay_t *netplay)
{
memset(&netplay->nat_traversal_state, 0, sizeof(netplay->nat_traversal_state));
netplay->nat_traversal_task_oustanding = true;
task_push_netplay_nat_traversal(&netplay->nat_traversal_state, netplay->tcp_port);
}

View File

@ -344,7 +344,7 @@ struct netplay
uint16_t tcp_port;
/* NAT traversal info (if NAT traversal is used and serving) */
bool nat_traversal;
bool nat_traversal, nat_traversal_task_oustanding;
struct natt_status nat_traversal_state;
struct delta_frame *buffer;