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.

80 lines
1.7 KiB

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. #include "xsync_errcode.hpp"
  13. namespace xsync {
  14. using namespace std;
  15. class XsyncNetAdd {
  16. public:
  17. XsyncNetAdd(){};
  18. XsyncNetAdd(string ip, uint32_t port) : ip(ip), port(port) {}
  19. string ip;
  20. uint32_t port;
  21. };
  22. class I_XSUDP {
  23. public:
  24. typedef function<void(XsyncNetAdd& from, uint8_t* data, size_t length)> onMessage_t;
  25. public:
  26. /**
  27. * @brief UDP
  28. *
  29. * @param ip localip default 0
  30. * @param localport localport
  31. * @return int
  32. */
  33. virtual xs_error_code_t initialize(string ip, int localport) = 0;
  34. /**
  35. * @brief UDP消息
  36. *
  37. * @param to
  38. * @param data
  39. * @param length
  40. * @return int
  41. * >0 ,
  42. * <0
  43. */
  44. virtual xs_error_code_t sendto(const XsyncNetAdd& to, const char* data, int32_t length, int32_t* sendlength) = 0;
  45. /**
  46. * @brief UDP消息
  47. *
  48. * @param data
  49. * @param length
  50. * @param from
  51. * @return int
  52. * >0 ,
  53. * <0
  54. */
  55. virtual xs_error_code_t receive(char* data, int32_t& length, XsyncNetAdd& from, int overtimems) = 0;
  56. /**
  57. * @brief UDP消息
  58. *
  59. * @param onMessage
  60. * @return xs_error_code_t
  61. */
  62. virtual xs_error_code_t startReceive(onMessage_t onMessage) = 0;
  63. virtual xs_error_code_t stopReceive() = 0;
  64. virtual xs_error_code_t clearRxBuffer() = 0;
  65. virtual ~I_XSUDP() {}
  66. };
  67. class I_XSUDPFactory {
  68. public:
  69. virtual shared_ptr<I_XSUDP> createXSUDP() = 0;
  70. };
  71. } // namespace xsync