TCPSocket.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Copyright @ 2015 Hangzhou Topzen Ltd.
  3. // Author: Tang (tang@hztopzen.com) @ 2015-07
  4. //
  5. #ifndef __TCPSOCKET_H
  6. #define __TCPSOCKET_H
  7. #include "Socket.h"
  8. namespace tzc {
  9. class TCPServer;
  10. class DECLDLL TCPSocket : public Socket
  11. {
  12. public:
  13. TCPSocket(TZ_Uint32 type = STYPE_TCP);
  14. TCPSocket(TZ_SOCKET sock, TZ_Uint32 type);
  15. TCPSocket(const Socket & sock);
  16. virtual ~TCPSocket();
  17. virtual TZ_INT Bind(const SockAddress & addr);
  18. virtual TZ_INT Connect(const SockAddress & raddr);
  19. // On success, return the number of characters received.
  20. // On error, -1 is returned
  21. virtual TZ_INT RecvBytes(TZ_BYTE * buffer, TZ_Uint32 length);
  22. // the following two functions have the same return value:
  23. // On success, return the number of characters sent.
  24. // On error, -1 is returned
  25. virtual TZ_INT SendBytes(const TZ_BYTE * buffer, TZ_Uint32 length);
  26. virtual TZ_INT SendBytes(const TZ_BYTE * buffer, TZ_Uint32 length,
  27. const SockAddress & raddr);
  28. public:
  29. TZ_INT SetLinger(TZ_BOOL on, TZ_Uint32 seconds);
  30. TZ_INT GetLinger(TZ_BOOL & on, TZ_Uint32 & seconds);
  31. TZ_INT SetNoDelay(TZ_BOOL flag);
  32. TZ_BOOL GetNoDelay();
  33. TZ_INT SetKeepAlive(TZ_BOOL flag);
  34. TZ_BOOL GetKeepAlive();
  35. // Sends one byte of urgent data through the socket
  36. TZ_INT SendUrgent(TZ_BYTE byte);
  37. friend class TCPServer;
  38. };
  39. }; // namespace tzc
  40. #endif /* ----- #ifndef __TCPSOCKET_H ----- */