lichao
2021-06-02 94f2a94f38261528d98a8ece4fcdb386cbca6566
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * =====================================================================================
 *
 *       Filename:  tcp_proxy.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年05月19日 15时04分15秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), lichao@aiotlink.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include "tcp_proxy.h"
#include "tcp_connection.h"
 
bool TcpProxy::Request(const std::string &ip, int port, std::string &&content, ReplyCB const &cb)
{
    if (content.empty()) { return false; }
    try {
        tcp::endpoint dest(ip::address::from_string(ip), port);
        TcpRequest1::Create(io_, dest, std::move(content), cb);
        LOG_TRACE() << "tcp request start " << ip << ':' << port;
        return true;
    } catch (std::exception &e) {
        LOG_ERROR() << "proxy request exception: " << e.what();
        return false;
    }
}