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.

82 lines
1.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SOCKETPORT_H_INCL__
  2. #define __SOCKETPORT_H_INCL__
  3. #include <errno.h> // Error number definitions
  4. #include <fcntl.h> // File control definitions
  5. #include <stdio.h> // standard input / output functions
  6. #include <stdlib.h>
  7. #include <string.h> // string function definitions
  8. #ifdef __linux__
  9. #include <netdb.h>
  10. #include <netinet/in.h>
  11. #include <sys/ioctl.h>
  12. #include <sys/socket.h>
  13. #include <sys/types.h>
  14. #include <unistd.h> // UNIX standard function definitions
  15. #else
  16. // #include <winsock.h>
  17. #include <windows.h>
  18. #include <winsock2.h>
  19. #include <ws2tcpip.h>
  20. #endif
  21. #include "transportSocket.h"
  22. /**
  23. * TODO: Add class description
  24. *
  25. * @author Gagua
  26. */
  27. class socketPort : public transportSocket
  28. {
  29. private:
  30. basicLogCollection * m_pLog;
  31. CSTR m_sHostName;
  32. #ifdef __linux__
  33. struct sockaddr_in serv_addr;
  34. int m_nSocketFD;
  35. #else
  36. SOCKET m_nSocketFD;
  37. #endif
  38. int m_nPort;
  39. bool m_bKeepAlive;
  40. bool _connect(void);
  41. protected:
  42. int sendBlock(unsigned char * Data, int DataSize);
  43. int recptBlock(unsigned char * Buffer, int * BufferLength);
  44. public:
  45. // Constructor
  46. socketPort();
  47. socketPort(CSTR URI);
  48. socketPort(CSTR Host, int Port, bool KeepALive = true);
  49. // Destructor
  50. virtual ~socketPort();
  51. bool disconnect(void);
  52. bool connectTo(CSTR Host, int Port);
  53. bool reconnect(void)
  54. {
  55. return _connect();
  56. }
  57. bool isConnected(void)
  58. {
  59. return m_bConnected;
  60. }
  61. void setKeepAlive(bool Param);
  62. bool getKeepAlive(void)
  63. {
  64. return m_bKeepAlive;
  65. }
  66. };
  67. #endif // __SOCKETPORT_H_INCL__