diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vmpi/tcpsocket_helpers.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/vmpi/tcpsocket_helpers.cpp')
| -rw-r--r-- | utils/vmpi/tcpsocket_helpers.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/utils/vmpi/tcpsocket_helpers.cpp b/utils/vmpi/tcpsocket_helpers.cpp new file mode 100644 index 0000000..c336b21 --- /dev/null +++ b/utils/vmpi/tcpsocket_helpers.cpp @@ -0,0 +1,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; +} |