CMessagePush.h 881 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "../pch/pch.h"
  3. using boost::asio::ip::tcp;
  4. class CClientMessage
  5. {
  6. public:
  7. int m_type; //消息类型 0:新的外卖订单
  8. std::string m_username;
  9. std::string m_order_id;
  10. std::string m_order_no;
  11. };
  12. class CMessagePush
  13. {
  14. public:
  15. CMessagePush(boost::asio::io_context& io_context)
  16. : socket_(io_context), m_io_context(io_context)
  17. {
  18. }
  19. ~CMessagePush();
  20. void Start();
  21. void Run();
  22. void StopWork()
  23. {
  24. m_is_work = false;
  25. }
  26. void PushMessage(std::string msg);
  27. //专门处理推送消息
  28. void HandleMessage(std::string msg);
  29. private:
  30. void handle_read(const boost::system::error_code& error,
  31. size_t bytes_transferred);
  32. void handle_write(const boost::system::error_code& error);
  33. private:
  34. bool m_is_work = true;
  35. boost::asio::io_context& m_io_context;
  36. tcp::socket socket_;
  37. enum { max_length = 1024 };
  38. char data_[max_length];
  39. };