This commit is contained in:
azw 2023-05-04 15:51:44 +00:00
parent 9dad68d86f
commit 5d69655f43
3 changed files with 22 additions and 1 deletions

View File

@ -16,6 +16,12 @@
const int PACK_MAX = 1024 * 64 * 2;
#ifdef USE_ASIO
UpStream::UpStream(asio::io_context& io_context):socket_(io_context)
{
}
#endif
void UpStream::Init(int instance_id, const std::string& remote_ip, int remote_port)
{
if (remote_ip.empty()) {

View File

@ -2,6 +2,10 @@
#include <f8/protoutils.h>
#ifdef USE_ASIO
#include <asio.hpp>
#endif
namespace a8
{
class TcpClient;
@ -26,6 +30,10 @@ class UpStream
a8::tick_t last_pong_tick = 0;
public:
#ifdef USE_ASIO
UpStream(asio::io_context& io_context);
#endif
void Init(int instance_id, const std::string& remote_ip, int remote_port);
void UnInit();
@ -67,6 +75,9 @@ class UpStream
char *recv_buff_ = nullptr;
unsigned int recv_bufflen_ = 0;
std::shared_ptr<a8::TcpClient> tcp_client_;
#ifdef USE_ASIO
asio::ip::tcp::socket socket_;
#endif
f8::TimerWp timer_wp_;
f8::Attacher attacher_;

View File

@ -55,8 +55,12 @@ std::weak_ptr<UpStream> UpStreamMgr::RecreateUpStream(const std::string& host, i
int instance_id = curr_id_;
std::string remote_ip = host;
int remote_port = port;
#ifdef USE_ASIO
asio::io_context io_context;
std::shared_ptr<UpStream> conn = std::make_shared<UpStream>(io_context);
#else
std::shared_ptr<UpStream> conn = std::make_shared<UpStream>();
#endif
conn->Init(instance_id, remote_ip, remote_port);
id_hash_[conn->instance_id] = conn;
key_hash_[key] = conn;