Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
951 B

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