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.

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