| | |
| | | #include <memory> |
| | | |
| | | class ShmSocket; |
| | | class NodeCenter; |
| | | typedef std::shared_ptr<Synced<NodeCenter>> CenterPtr; |
| | | |
| | | class TcpRequest1 : public std::enable_shared_from_this<TcpRequest1> |
| | | { |
| | | public: |
| | | static void Create(boost::asio::io_context &io, tcp::endpoint const &addr, std::string request, ShmSocket &shm_socket) |
| | | static void Create(boost::asio::io_context &io, tcp::endpoint const &addr, std::string request, ReplyCB const &cb) |
| | | { |
| | | std::make_shared<TcpRequest1>(io, addr, std::move(request), shm_socket)->Start(); |
| | | std::make_shared<TcpRequest1>(io, addr, std::move(request), cb)->Start(); |
| | | } |
| | | |
| | | TcpRequest1(boost::asio::io_context &io, tcp::endpoint const &addr, std::string request, ShmSocket &shm_socket) : |
| | | socket_(io), shm_socket_(shm_socket), remote_(addr), request_(std::move(request)) {} |
| | | TcpRequest1(boost::asio::io_context &io, tcp::endpoint const &addr, std::string request, ReplyCB const &cb) : |
| | | socket_(io), reply_cb_(cb), remote_(addr), request_(std::move(request)) {} |
| | | void OnError(bserror_t ec); |
| | | |
| | | private: |
| | | void Start(); |
| | | void Close(); |
| | | void OnRead(size_t size); |
| | | void SendReply(BHMsgHead &head, std::string body_content); |
| | | |
| | | tcp::socket socket_; |
| | | ShmSocket &shm_socket_; // send reply |
| | | ReplyCB reply_cb_; |
| | | tcp::endpoint remote_; |
| | | std::string request_; |
| | | std::vector<char> recv_buffer_; |
| | |
| | | class TcpReply1 : public std::enable_shared_from_this<TcpReply1> |
| | | { |
| | | public: |
| | | typedef std::shared_ptr<Synced<NodeCenter>> CenterPtr; |
| | | static void Create(tcp::socket sock, CenterPtr pscenter) |
| | | { |
| | | std::make_shared<TcpReply1>(std::move(sock), pscenter)->Start(); |