UDPSocket.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Copyright @ 2015 Hangzhou Topzen Ltd.
  3. // Author: Tang (tang@hztopzen.com) @ 2015-07
  4. //
  5. #ifndef __UDPSOCKET_H
  6. #define __UDPSOCKET_H
  7. #include "Socket.h"
  8. namespace tzc {
  9. class DECLDLL UDPSocket : public Socket
  10. {
  11. public:
  12. UDPSocket(TZ_Uint32 type = STYPE_UDP);
  13. UDPSocket(const Socket & sock);
  14. virtual ~UDPSocket();
  15. virtual TZ_INT Bind(const SockAddress & addr);
  16. virtual TZ_INT Connect(const SockAddress & raddr);
  17. // On success, return the number of characters received.
  18. // On error, -1 is returned
  19. virtual TZ_INT RecvBytes(TZ_BYTE * buffer, TZ_Uint32 length);
  20. // the following two functions have the same return value:
  21. // On success, return the number of characters sent.
  22. // On error, -1 is returned
  23. virtual TZ_INT SendBytes(const TZ_BYTE * buffer, TZ_Uint32 length);
  24. virtual TZ_INT SendBytes(const TZ_BYTE * buffer, TZ_Uint32 length,
  25. const SockAddress & raddr);
  26. virtual SockAddress PeerAddress() const;
  27. public:
  28. TZ_INT SetBroadcast(TZ_BOOL on);
  29. TZ_BOOL GetBroadcast();
  30. private:
  31. SockAddress m_raddr;
  32. };
  33. //
  34. // inlines
  35. //
  36. inline SockAddress UDPSocket::PeerAddress() const
  37. {
  38. return m_raddr;
  39. }
  40. }; // namespace tzc
  41. #endif /* ----- #ifndef __UDPSOCKET_H ----- */