1
This commit is contained in:
parent
5d69655f43
commit
b064aed353
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
#include <a8/asiotcpclient.h>
|
||||||
|
#else
|
||||||
#include <a8/tcpclient.h>
|
#include <a8/tcpclient.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <f8/udplog.h>
|
#include <f8/udplog.h>
|
||||||
#include <f8/timer.h>
|
#include <f8/timer.h>
|
||||||
@ -16,12 +20,6 @@
|
|||||||
|
|
||||||
const int PACK_MAX = 1024 * 64 * 2;
|
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)
|
void UpStream::Init(int instance_id, const std::string& remote_ip, int remote_port)
|
||||||
{
|
{
|
||||||
if (remote_ip.empty()) {
|
if (remote_ip.empty()) {
|
||||||
@ -34,7 +32,11 @@ void UpStream::Init(int instance_id, const std::string& remote_ip, int remote_po
|
|||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
last_pong_tick = a8::XGetTickCount();
|
last_pong_tick = a8::XGetTickCount();
|
||||||
recv_buff_ = (char*) malloc(PACK_MAX * 2);
|
recv_buff_ = (char*) malloc(PACK_MAX * 2);
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
tcp_client_ = std::make_shared<a8::AsioTcpClient>();
|
||||||
|
#else
|
||||||
tcp_client_ = std::make_shared<a8::TcpClient>();
|
tcp_client_ = std::make_shared<a8::TcpClient>();
|
||||||
|
#endif
|
||||||
tcp_client_->remote_address = remote_ip;
|
tcp_client_->remote_address = remote_ip;
|
||||||
tcp_client_->remote_port = remote_port;
|
tcp_client_->remote_port = remote_port;
|
||||||
tcp_client_->on_error = std::bind(&UpStream::on_error, this, std::placeholders::_1, std::placeholders::_2);
|
tcp_client_->on_error = std::bind(&UpStream::on_error, this, std::placeholders::_1, std::placeholders::_2);
|
||||||
@ -154,7 +156,11 @@ void UpStream::ForwardClientMsgEx(f8::MsgHdr* hdr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
void UpStream::on_error(a8::AsioTcpClient* sender, int errorId)
|
||||||
|
#else
|
||||||
void UpStream::on_error(a8::TcpClient* sender, int errorId)
|
void UpStream::on_error(a8::TcpClient* sender, int errorId)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
f8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d",
|
f8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d",
|
||||||
{
|
{
|
||||||
@ -164,7 +170,11 @@ void UpStream::on_error(a8::TcpClient* sender, int errorId)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
void UpStream::on_connect(a8::AsioTcpClient* sender)
|
||||||
|
#else
|
||||||
void UpStream::on_connect(a8::TcpClient* sender)
|
void UpStream::on_connect(a8::TcpClient* sender)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
f8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d",
|
f8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d",
|
||||||
@ -184,7 +194,11 @@ void UpStream::on_connect(a8::TcpClient* sender)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
void UpStream::on_disconnect(a8::AsioTcpClient* sender)
|
||||||
|
#else
|
||||||
void UpStream::on_disconnect(a8::TcpClient* sender)
|
void UpStream::on_disconnect(a8::TcpClient* sender)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
f8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect "
|
f8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect "
|
||||||
@ -206,7 +220,11 @@ void UpStream::on_disconnect(a8::TcpClient* sender)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
void UpStream::on_socketread(a8::AsioTcpClient* sender, char* buf, unsigned int len)
|
||||||
|
#else
|
||||||
void UpStream::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
|
void UpStream::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
++App::Instance()->perf.read_count;
|
++App::Instance()->perf.read_count;
|
||||||
|
@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
#include <f8/protoutils.h>
|
#include <f8/protoutils.h>
|
||||||
|
|
||||||
#ifdef USE_ASIO
|
|
||||||
#include <asio.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
class TcpClient;
|
class TcpClient;
|
||||||
|
class AsioTcpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UpStreamMsgNode
|
struct UpStreamMsgNode
|
||||||
@ -30,9 +27,6 @@ class UpStream
|
|||||||
a8::tick_t last_pong_tick = 0;
|
a8::tick_t last_pong_tick = 0;
|
||||||
|
|
||||||
public:
|
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 Init(int instance_id, const std::string& remote_ip, int remote_port);
|
||||||
void UnInit();
|
void UnInit();
|
||||||
@ -62,10 +56,17 @@ class UpStream
|
|||||||
void ForwardClientMsgEx(f8::MsgHdr* hdr);
|
void ForwardClientMsgEx(f8::MsgHdr* hdr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef USE_ASIO
|
||||||
|
void on_error(a8::AsioTcpClient* sender, int errorId);
|
||||||
|
void on_connect(a8::AsioTcpClient* sender);
|
||||||
|
void on_disconnect(a8::AsioTcpClient* sender);
|
||||||
|
void on_socketread(a8::AsioTcpClient* sender, char* buf, unsigned int len);
|
||||||
|
#else
|
||||||
void on_error(a8::TcpClient* sender, int errorId);
|
void on_error(a8::TcpClient* sender, int errorId);
|
||||||
void on_connect(a8::TcpClient* sender);
|
void on_connect(a8::TcpClient* sender);
|
||||||
void on_disconnect(a8::TcpClient* sender);
|
void on_disconnect(a8::TcpClient* sender);
|
||||||
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
||||||
|
#endif
|
||||||
|
|
||||||
void CheckAlive();
|
void CheckAlive();
|
||||||
void AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg,
|
void AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg,
|
||||||
@ -74,9 +75,10 @@ class UpStream
|
|||||||
private:
|
private:
|
||||||
char *recv_buff_ = nullptr;
|
char *recv_buff_ = nullptr;
|
||||||
unsigned int recv_bufflen_ = 0;
|
unsigned int recv_bufflen_ = 0;
|
||||||
std::shared_ptr<a8::TcpClient> tcp_client_;
|
|
||||||
#ifdef USE_ASIO
|
#ifdef USE_ASIO
|
||||||
asio::ip::tcp::socket socket_;
|
std::shared_ptr<a8::AsioTcpClient> tcp_client_;
|
||||||
|
#else
|
||||||
|
std::shared_ptr<a8::TcpClient> tcp_client_;
|
||||||
#endif
|
#endif
|
||||||
f8::TimerWp timer_wp_;
|
f8::TimerWp timer_wp_;
|
||||||
f8::Attacher attacher_;
|
f8::Attacher attacher_;
|
||||||
|
@ -55,12 +55,7 @@ std::weak_ptr<UpStream> UpStreamMgr::RecreateUpStream(const std::string& host, i
|
|||||||
int instance_id = curr_id_;
|
int instance_id = curr_id_;
|
||||||
std::string remote_ip = host;
|
std::string remote_ip = host;
|
||||||
int remote_port = port;
|
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>();
|
std::shared_ptr<UpStream> conn = std::make_shared<UpStream>();
|
||||||
#endif
|
|
||||||
conn->Init(instance_id, remote_ip, remote_port);
|
conn->Init(instance_id, remote_ip, remote_port);
|
||||||
id_hash_[conn->instance_id] = conn;
|
id_hash_[conn->instance_id] = conn;
|
||||||
key_hash_[key] = conn;
|
key_hash_[key] = conn;
|
||||||
|
2
third_party/a8
vendored
2
third_party/a8
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 54fe50edf11dda774dcd6fc480134c9e4ce449cd
|
Subproject commit c5e180a96a7ba0d89f41f28821b0eb081f7ee880
|
2
third_party/f8
vendored
2
third_party/f8
vendored
@ -1 +1 @@
|
|||||||
Subproject commit ae5c84ae98a314a6f29a2e29e9a2937801324c15
|
Subproject commit e8e6a85b8f00a248eea7aea80276c6f1afd98ef9
|
Loading…
x
Reference in New Issue
Block a user