Skip to content

Commit

Permalink
engine: network: fix async NS resolve
Browse files Browse the repository at this point in the history
If we're currently running NS resolving thread, any request would block.

Co-Authored-by: mittorn <[email protected]>
  • Loading branch information
a1batross and mittorn committed Oct 24, 2023
1 parent 8f819a2 commit 9e107e9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion engine/common/net_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ static void NET_InitializeCriticalSections( void )
void NET_ResolveThread( void )
{
struct sockaddr_storage addr;
qboolean res;

RESOLVE_DBG( "[resolve thread] starting resolve for " );
RESOLVE_DBG( nsthread.hostname );
Expand All @@ -453,13 +454,14 @@ void NET_ResolveThread( void )
RESOLVE_DBG( " with gethostbyname\n" );
#endif

if( NET_GetHostByName( nsthread.hostname, nsthread.family, &addr ))
if(( res = NET_GetHostByName( nsthread.hostname, nsthread.family, &addr )))
RESOLVE_DBG( "[resolve thread] success\n" );
else
RESOLVE_DBG( "[resolve thread] failed\n" );
mutex_lock( &nsthread.mutexres );
nsthread.addr = addr;
nsthread.busy = false;
nsthread.result = res ? NET_EAI_OK : NET_EAI_NONAME;
RESOLVE_DBG( "[resolve thread] returning result\n" );
mutex_unlock( &nsthread.mutexres );
RESOLVE_DBG( "[resolve thread] exiting thread\n" );
Expand Down Expand Up @@ -544,6 +546,7 @@ static net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_stor
memset( &nsthread.addr, 0, sizeof( nsthread.addr ));

detach_thread( nsthread.thread );
asyncfailed = false;
}
else
{
Expand Down

0 comments on commit 9e107e9

Please sign in to comment.