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.

45 lines
917 B

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef UDP_SOCKET_H
  7. #define UDP_SOCKET_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/netadr.h"
  12. #include "tier0/basetypes.h"
  13. class CUtlBuffer;
  14. // Creates a non-blocking UPD socket
  15. class CUDPSocket
  16. {
  17. public:
  18. CUDPSocket();
  19. ~CUDPSocket();
  20. bool Init( unsigned short bindToPort );
  21. void Shutdown();
  22. bool RecvFrom( netadr_t& packet_from, CUtlBuffer& data );
  23. bool SendTo( const netadr_t &recipient, const CUtlBuffer& data );
  24. bool SendTo( const netadr_t &recipient, const byte *data, size_t datalength );
  25. bool IsValid() const { return m_Socket != 0; }
  26. protected:
  27. bool CreateSocket (void);
  28. class CImpl;
  29. CImpl *m_pImpl;
  30. netadr_t m_socketIP;
  31. unsigned int m_Socket;
  32. unsigned short m_Port;
  33. };
  34. #endif // UDP_SOCKET_H