blob: c336b21439beacd7f941ec944af03a7b111f38b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include <windows.h>
#include "tcpsocket_helpers.h"
// This connects to an ISocket listening with Listen().
bool TCPSocket_Connect( ITCPSocket *pSocket, const CIPAddr *pAddr, double flTimeout )
{
pSocket->BeginConnect( *pAddr );
CWaitTimer waitTimer( flTimeout );
while ( 1 )
{
if ( pSocket->UpdateConnect() )
return true;
if ( waitTimer.ShouldKeepWaiting() )
Sleep( 10 );
else
break;
}
return false;
}
ITCPSocket* TCPSocket_ListenForOneConnection( ITCPListenSocket *pSocket, CIPAddr *pAddr, double flTimeout )
{
CWaitTimer waitTimer( flTimeout );
while ( 1 )
{
ITCPSocket *pRet = pSocket->UpdateListen( pAddr );
if ( pRet )
return pRet;
if ( waitTimer.ShouldKeepWaiting() )
Sleep( 10 );
else
break;
}
return NULL;
}
|