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.

84 lines
2.1 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
5 years ago
​
7 years ago
​
​
​
​
​
​
​
5 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
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 "../transport/transportSocket.h"
  22. #define MAX_HOST_STRING_SIZE 128
  23. /**
  24. * TODO: Add class description
  25. *
  26. * @author Gagua
  27. */
  28. class clientPort : public transportSocket {
  29. private:
  30. basicLogCollection *m_pLog;
  31. char m_cHostName[MAX_HOST_STRING_SIZE];
  32. #ifdef __linux__
  33. int m_nSocketFD;
  34. #else
  35. SOCKET m_nSocketFD;
  36. #endif
  37. int m_nPort;
  38. bool m_bKeepAlive;
  39. bool _connect( void );
  40. protected:
  41. int sendBlock(unsigned char *Data, int DataSize);
  42. int recptBlock(unsigned char *Buffer, int *BufferLength);
  43. public:
  44. // Constructor
  45. clientPort();
  46. clientPort(CSTR URI);
  47. clientPort(CSTR Host, int Port, bool KeepALive = true);
  48. // Destructor
  49. virtual ~clientPort();
  50. virtual bool create();
  51. bool disconnect(void);
  52. bool connectTo(CSTR Host, int Port);
  53. bool reconnect(void){
  54. return _connect();;
  55. };
  56. bool isConnected(void){ return getConnectionStatus() == CS_CONNECTED; };
  57. void setKeepAlive(bool Param);
  58. bool getKeepAlive(void){ return m_bKeepAlive; };
  59. };
  60. // TODO: Uncomment the copy constructor when you need it.
  61. //inline socketPort::socketPort(const socketPort& src)
  62. //{
  63. // // TODO: copy
  64. //}
  65. // TODO: Uncomment the assignment operator when you need it.
  66. //inline socketPort& socketPort::operator=(const socketPort& rhs)
  67. //{
  68. // if (this == &rhs) {
  69. // return *this;
  70. // }
  71. //
  72. // // TODO: assignment
  73. //
  74. // return *this;
  75. //}
  76. #endif // __SOCKETPORT_H_INCL__