ServerDlg.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // ServerDlg.h : header file
  2. //
  3. #pragma once
  4. #include "afxwin.h"
  5. #include "../../../Src/HPSocket.h"
  6. #include "../../Global/helper.h"
  7. class CServerDlg;
  8. class CTcpServerListenerImpl : public CTcpServerListener
  9. {
  10. public:
  11. CTcpServerListenerImpl(CServerDlg* pDlg) : m_pDlg(pDlg)
  12. {
  13. }
  14. private:
  15. virtual EnHandleResult OnPrepareListen(SOCKET soListen);
  16. virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength);
  17. virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength);
  18. virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode);
  19. virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient);
  20. virtual EnHandleResult OnShutdown();
  21. private:
  22. void DetachConnInfo(CONNID dwConnID);
  23. BOOL ParseRequestHeader(BYTE*& pData, int& iLength, BOOL& isHttps, CString& strAddr, USHORT& usPort);
  24. BOOL CheckIfHttp(const BYTE* pData, int iLength);
  25. public:
  26. CServerDlg* m_pDlg;
  27. };
  28. class CTcpAgentListenerImpl : public CTcpAgentListener
  29. {
  30. public:
  31. CTcpAgentListenerImpl(CServerDlg* pDlg) : m_pDlg(pDlg)
  32. {
  33. }
  34. private:
  35. virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength);
  36. virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength);
  37. virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode);
  38. virtual EnHandleResult OnConnect(CONNID dwConnID);
  39. virtual EnHandleResult OnShutdown();
  40. private:
  41. void DetachConnInfo(CONNID dwConnID);
  42. public:
  43. CServerDlg* m_pDlg;
  44. };
  45. // CServerDlg dialog
  46. class CServerDlg : public CDialogEx
  47. {
  48. // Construction
  49. public:
  50. CServerDlg(CWnd* pParent = nullptr); // standard constructor
  51. // Dialog Data
  52. enum { IDD = IDD_SERVER_DIALOG };
  53. protected:
  54. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  55. virtual BOOL PreTranslateMessage(MSG* pMsg);
  56. // Implementation
  57. protected:
  58. HICON m_hIcon;
  59. // Generated message map functions
  60. virtual BOOL OnInitDialog();
  61. afx_msg void OnPaint();
  62. afx_msg HCURSOR OnQueryDragIcon();
  63. afx_msg void OnBnClickedStart();
  64. afx_msg void OnBnClickedStop();
  65. afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp);
  66. afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex);
  67. afx_msg void OnBnClickedOptions();
  68. afx_msg void OnClose();
  69. DECLARE_MESSAGE_MAP()
  70. public:
  71. void SetAppState(EnAppState state);
  72. private:
  73. CListBox m_Info;
  74. CEdit m_Port;
  75. CButton m_Start;
  76. CButton m_Stop;
  77. CButton m_Options;
  78. CButton m_ShowLog;
  79. EnAppState m_enState;
  80. public:
  81. smart_simple_ptr<CTcpServerListenerImpl> m_pServerListener;
  82. smart_simple_ptr<CTcpAgentListenerImpl> m_pAgentListener;
  83. CTcpServerPtr m_Server;
  84. CTcpAgentPtr m_Agent;
  85. BOOL m_bLog;
  86. };