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.

94 lines
1.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <fstream>
  3. #include <functional>
  4. #include <iostream>
  5. #include <list>
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <sstream>
  10. #include <string>
  11. #include <vector>
  12. namespace iflytop {
  13. using namespace std;
  14. typedef enum {
  15. kxs_ec_success = 0,
  16. kxs_ec_overtime,
  17. kxs_ec_socket_fail,
  18. kxs_ec_bind_fail,
  19. kxs_ec_send_fail,
  20. kxs_ec_receive_fail,
  21. kxs_ec_setsockopt_rx_timeout_fail,
  22. } xs_error_code_t;
  23. class XsyncNetAdd {
  24. public:
  25. uint32_t ip;
  26. uint32_t port;
  27. };
  28. class I_XSUDPListener {
  29. public:
  30. typedef function<void(XsyncNetAdd& from, uint8_t* data, size_t length)> onMessage_t;
  31. public:
  32. /**
  33. * @brief UDP
  34. *
  35. * @param ip localip default 0
  36. * @param localport localport
  37. * @param onMessage UDP消息监听
  38. * @return int
  39. */
  40. virtual xs_error_code_t initialize(string ip, int localport, onMessage_t onMessage) = 0;
  41. virtual ~I_XSUDPListener() {}
  42. };
  43. class I_XSUDP {
  44. public:
  45. /**
  46. * @brief UDP
  47. *
  48. * @param ip localip default 0
  49. * @param localport localport
  50. * @return int
  51. */
  52. virtual xs_error_code_t initialize(string ip, int localport) = 0;
  53. /**
  54. * @brief UDP消息
  55. *
  56. * @param to
  57. * @param data
  58. * @param length
  59. * @return int
  60. */
  61. virtual xs_error_code_t sendto(const XsyncNetAdd& to, const char* data, int32_t length) = 0;
  62. /**
  63. * @brief UDP消息
  64. *
  65. * @param data
  66. * @param length
  67. * @param from
  68. * @return int
  69. */
  70. virtual xs_error_code_t receive(const char* data, int32_t length, XsyncNetAdd& from, int overtimems) = 0;
  71. virtual ~I_XSUDP() {}
  72. };
  73. class I_XSyncUDPFactory {
  74. public:
  75. virtual shared_ptr<I_XSUDPListener> createXSUDPListener() = 0;
  76. virtual shared_ptr<I_XSUDP> createXSUDP() = 0;
  77. };
  78. class Xsync {
  79. private:
  80. /* data */
  81. public:
  82. Xsync(/* args */);
  83. ~Xsync();
  84. };
  85. } // namespace iflytop