/*
|
* =====================================================================================
|
*
|
* Filename: tcp_connection.h
|
*
|
* Description:
|
*
|
* Version: 1.0
|
* Created: 2021年05月25日 15时34分12秒
|
* Revision: none
|
* Compiler: gcc
|
*
|
* Author: Li Chao (), lichao@aiotlink.com
|
* Organization:
|
*
|
* =====================================================================================
|
*/
|
#ifndef TCP_CONNECTION_H373GIL5
|
#define TCP_CONNECTION_H373GIL5
|
|
#include "bh_util.h"
|
#include "node_center.h"
|
#include "tcp_common.h"
|
#include <functional>
|
#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, ReplyCB const &cb)
|
{
|
std::make_shared<TcpRequest1>(io, addr, std::move(request), cb)->Start();
|
}
|
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_;
|
ReplyCB reply_cb_;
|
tcp::endpoint remote_;
|
std::string request_;
|
std::vector<char> recv_buffer_;
|
size_t recv_len_ = 0;
|
};
|
|
class NodeCenter;
|
class TcpReply1 : public std::enable_shared_from_this<TcpReply1>
|
{
|
public:
|
static void Create(tcp::socket sock, CenterPtr pscenter)
|
{
|
std::make_shared<TcpReply1>(std::move(sock), pscenter)->Start();
|
}
|
|
TcpReply1(tcp::socket sock, CenterPtr pscenter) :
|
socket_(std::move(sock)), pscenter_(pscenter) {}
|
void OnError(bserror_t ec);
|
|
private:
|
void Start();
|
void Close();
|
void OnRead(size_t size);
|
|
tcp::socket socket_;
|
CenterPtr pscenter_;
|
std::vector<char> recv_buffer_;
|
uint32_t recv_len_ = 0;
|
std::string send_buffer_;
|
};
|
|
#endif // end of include guard: TCP_CONNECTION_H373GIL5
|