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.9 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
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. XsyncNetAdd(){};
  26. XsyncNetAdd(string ip, uint32_t port) : ip(ip), port(port) {}
  27. string ip;
  28. uint32_t port;
  29. };
  30. class I_XSUDP {
  31. public:
  32. typedef function<void(XsyncNetAdd& from, uint8_t* data, size_t length)> onMessage_t;
  33. public:
  34. /**
  35. * @brief UDP
  36. *
  37. * @param ip localip default 0
  38. * @param localport localport
  39. * @return int
  40. */
  41. virtual xs_error_code_t initialize(string ip, int localport) = 0;
  42. /**
  43. * @brief UDP消息
  44. *
  45. * @param to
  46. * @param data
  47. * @param length
  48. * @return int
  49. * >0 ,
  50. * <0
  51. */
  52. virtual xs_error_code_t sendto(const XsyncNetAdd& to, const char* data, int32_t length, int32_t* sendlength) = 0;
  53. /**
  54. * @brief UDP消息
  55. *
  56. * @param data
  57. * @param length
  58. * @param from
  59. * @return int
  60. * >0 ,
  61. * <0
  62. */
  63. virtual xs_error_code_t receive(char* data, int32_t& length, XsyncNetAdd& from, int overtimems) = 0;
  64. /**
  65. * @brief UDP消息
  66. *
  67. * @param onMessage
  68. * @return xs_error_code_t
  69. */
  70. virtual xs_error_code_t startReceive(onMessage_t onMessage) = 0;
  71. virtual ~I_XSUDP() {}
  72. };
  73. class I_XSyncUDPFactory {
  74. public:
  75. virtual shared_ptr<I_XSUDP> createXSUDP() = 0;
  76. };
  77. class Xsync {
  78. private:
  79. /* data */
  80. public:
  81. Xsync(/* args */);
  82. ~Xsync();
  83. };
  84. } // namespace iflytop