/*
|
* =====================================================================================
|
*
|
* 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 "tcp_common.h"
|
#include <functional>
|
#include <memory>
|
|
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)
|
{
|
std::make_shared<TcpRequest1>(io, addr, std::move(request))->Connect();
|
}
|
|
TcpRequest1(boost::asio::io_context &io, tcp::endpoint const &addr, std::string request);
|
|
private:
|
void Connect();
|
void Close();
|
void SendRequest();
|
void ReadReply();
|
|
tcp::socket socket_;
|
tcp::endpoint remote_;
|
std::string request_;
|
std::vector<char> buffer_;
|
};
|
|
class TcpReply1 : public std::enable_shared_from_this<TcpReply1>
|
{
|
public:
|
static void Create(tcp::socket sock)
|
{
|
std::make_shared<TcpReply1>(std::move(sock))->Start();
|
}
|
|
TcpReply1(tcp::socket sock);
|
void Start();
|
|
private:
|
tcp::socket socket_;
|
std::vector<char> recv_buffer_;
|
std::string send_buffer_;
|
};
|
|
#endif // end of include guard: TCP_CONNECTION_H373GIL5
|