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.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SERVLET_WEB_SOCKET_CLIENT_HANDLER_HEADER__
  2. #define __SERVLET_WEB_SOCKET_CLIENT_HANDLER_HEADER__
  3. #include "../../components/base/basicThread.h"
  4. #include "../../alg/generic/libzip.h"
  5. #include <sys/types.h> /* See NOTES */
  6. #include <sys/socket.h>
  7. #include <poll.h>
  8. #include <vector>
  9. typedef struct S_WS_FRAME_HEADER_B0{
  10. union {
  11. uint8_t byte;
  12. struct{
  13. uint8_t OPCODE: 4;
  14. uint8_t RSV3: 1;
  15. uint8_t RSV2: 1;
  16. uint8_t RSV1: 1;
  17. uint8_t FIN: 1;
  18. } bits;
  19. };
  20. } WS_FRAME_HEADER_B0;
  21. typedef struct S_WS_FRAME_HEADER_B1{
  22. union {
  23. uint8_t byte;
  24. struct{
  25. uint8_t PLEN0: 7;
  26. uint8_t MASK: 1;
  27. } bits;
  28. };
  29. } WS_FRAME_HEADER_B1;
  30. typedef struct S_WS_FRAME_HEADER{
  31. union {
  32. uint16_t word;
  33. struct{
  34. uint16_t OPCODE: 4;
  35. uint16_t RSV3: 1;
  36. uint16_t RSV2: 1;
  37. uint16_t RSV1: 1;
  38. uint16_t FIN: 1;
  39. uint16_t PLEN0: 7;
  40. uint16_t MASK: 1;
  41. }bits;
  42. };
  43. uint16_t PLE_MASK1;
  44. uint16_t PLE_MASK2;
  45. uint16_t PLE3;
  46. uint16_t PLE4;
  47. uint16_t MASK3;
  48. uint16_t MASK4;
  49. } WS_FRAME_HEADER;
  50. typedef enum E_WS_OPCODE{
  51. WS_OC_CONTINUATION = 0x0,
  52. WS_OC_TEXT = 0x1,
  53. WS_OC_BINARY = 0x2,
  54. WS_OC_CLOSE = 0x8,
  55. WS_OC_PING = 0x9,
  56. WS_OC_PONG = 0xA
  57. } WS_OPCODE;
  58. class servletWS;
  59. class servletClientHandlerWS: public basicThread{
  60. private:
  61. basicLogCollection * m_pLog;
  62. int m_iSocketFID;
  63. servletWS * m_pParent;
  64. zipDataPackage * m_pDeflatener;
  65. bool m_bDeflatePerMessage;
  66. bool parseFrame(){ return true; };
  67. bool assembleFrame( bool FIN, bool RSV1, bool RSV2, bool RSV3, WS_OPCODE code, uint8_t *in_buffer, size_t in_size, uint8_t *&out_buffer, size_t &out_size, bool bmask=false, uint32_t mask=0xffff );
  68. public:
  69. explicit servletClientHandlerWS( servletWS *pPtr, int Socket );
  70. ~servletClientHandlerWS();
  71. virtual void m_fThreadProc( void );
  72. };
  73. typedef std::vector<servletClientHandlerWS*> vectorClientHandlerWS;
  74. #endif