| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #pragma once
- #include "../pch/pch.h"
- using boost::asio::ip::tcp;
- class CClientMessage
- {
- public:
- int m_type; //消息类型 0:新的外卖订单
- std::string m_username;
- std::string m_order_id;
- std::string m_order_no;
- };
- class CMessagePush
- {
- public:
- CMessagePush(boost::asio::io_context& io_context)
- : socket_(io_context), m_io_context(io_context)
- {
- }
- ~CMessagePush();
- void Start();
- void StopWork()
- {
- m_is_work = false;
- }
- void PushMessage(std::string msg);
- //专门处理推送消息
- void HandleMessage(std::string msg);
- private:
- void handle_read(const boost::system::error_code& error,
- size_t bytes_transferred);
- void handle_write(const boost::system::error_code& error);
- private:
- bool m_is_work = true;
- boost::asio::io_context& m_io_context;
- tcp::socket socket_;
- enum { max_length = 1024 };
- char data_[max_length];
- };
|