CMessagePush.h 867 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 StopWork()
  22. {
  23. m_is_work = false;
  24. }
  25. void PushMessage(std::string msg);
  26. //专门处理推送消息
  27. void HandleMessage(std::string msg);
  28. private:
  29. void handle_read(const boost::system::error_code& error,
  30. size_t bytes_transferred);
  31. void handle_write(const boost::system::error_code& error);
  32. private:
  33. bool m_is_work = true;
  34. boost::asio::io_context& m_io_context;
  35. tcp::socket socket_;
  36. enum { max_length = 1024 };
  37. char data_[max_length];
  38. };