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.

81 lines
2.0 KiB

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