1
This commit is contained in:
parent
13c40acd30
commit
c64eba3f15
@ -9,7 +9,7 @@ App::App()
|
|||||||
|
|
||||||
const std::string App::GetPkgName()
|
const std::string App::GetPkgName()
|
||||||
{
|
{
|
||||||
return "";
|
return "mangosd";
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::Init()
|
void App::Init()
|
||||||
|
1
third_party/f8/f8/iomgr.h
vendored
1
third_party/f8/f8/iomgr.h
vendored
@ -21,6 +21,7 @@ namespace f8
|
|||||||
private:
|
private:
|
||||||
std::vector<std::vector<std::shared_ptr<asio::io_context::work>>> io_works_;
|
std::vector<std::vector<std::shared_ptr<asio::io_context::work>>> io_works_;
|
||||||
std::vector<std::vector<std::shared_ptr<asio::io_context>>> io_contexts_;
|
std::vector<std::vector<std::shared_ptr<asio::io_context>>> io_contexts_;
|
||||||
|
friend class TcpClient;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
19
third_party/f8/f8/tcpclient.cc
vendored
19
third_party/f8/f8/tcpclient.cc
vendored
@ -4,13 +4,28 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <f8/tcpclient.h>
|
#include <f8/tcpclient.h>
|
||||||
|
#include <f8/iomgr.h>
|
||||||
|
|
||||||
const int MAX_RECV_BUFFERSIZE = 1024 * 64;
|
const int MAX_RECV_BUFFERSIZE = 1024 * 64;
|
||||||
|
|
||||||
namespace f8
|
namespace f8
|
||||||
{
|
{
|
||||||
|
|
||||||
TcpClient::TcpClient(std::shared_ptr<asio::io_context> io_context, const std::string& remote_ip, int remote_port)
|
TcpClient::TcpClient(std::shared_ptr<asio::io_context> io_context,
|
||||||
|
const std::string& remote_ip,
|
||||||
|
int remote_port)
|
||||||
|
{
|
||||||
|
Init(io_context, remote_ip, remote_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpClient::TcpClient(const std::string& remote_ip, int remote_port)
|
||||||
|
{
|
||||||
|
Init(f8::IoMgr::Instance()->GetIoContext(0), remote_ip, remote_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::Init(std::shared_ptr<asio::io_context> io_context,
|
||||||
|
const std::string& remote_ip,
|
||||||
|
int remote_port)
|
||||||
{
|
{
|
||||||
io_context_ = io_context;
|
io_context_ = io_context;
|
||||||
remote_address_ = remote_ip;
|
remote_address_ = remote_ip;
|
||||||
@ -18,7 +33,7 @@ namespace f8
|
|||||||
endpoint_ = std::make_shared<asio::ip::tcp::endpoint>
|
endpoint_ = std::make_shared<asio::ip::tcp::endpoint>
|
||||||
(
|
(
|
||||||
asio::ip::address::from_string(remote_address_),
|
asio::ip::address::from_string(remote_address_),
|
||||||
remote_port_
|
remote_port_
|
||||||
);
|
);
|
||||||
send_buffer_mutex_ = std::make_shared<std::mutex>();
|
send_buffer_mutex_ = std::make_shared<std::mutex>();
|
||||||
socket_ = std::make_shared<asio::ip::tcp::socket>(*io_context);
|
socket_ = std::make_shared<asio::ip::tcp::socket>(*io_context);
|
||||||
|
9
third_party/f8/f8/tcpclient.h
vendored
9
third_party/f8/f8/tcpclient.h
vendored
@ -14,9 +14,11 @@ namespace f8
|
|||||||
std::function<void (f8::TcpClient*)> on_connect;
|
std::function<void (f8::TcpClient*)> on_connect;
|
||||||
std::function<void (f8::TcpClient*, int)> on_disconnect;
|
std::function<void (f8::TcpClient*, int)> on_disconnect;
|
||||||
std::function<void (f8::TcpClient*, char*, unsigned int)> on_socketread;
|
std::function<void (f8::TcpClient*, char*, unsigned int)> on_socketread;
|
||||||
|
|
||||||
TcpClient(std::shared_ptr<asio::io_context> io_context,
|
TcpClient(std::shared_ptr<asio::io_context> io_context,
|
||||||
const std::string& remote_ip,
|
const std::string& remote_ip,
|
||||||
int remote_port);
|
int remote_port);
|
||||||
|
TcpClient(const std::string& remote_ip, int remote_port);
|
||||||
virtual ~TcpClient();
|
virtual ~TcpClient();
|
||||||
const std::string& GetRemoteAddress() { return remote_address_; }
|
const std::string& GetRemoteAddress() { return remote_address_; }
|
||||||
int GetRemotePort() { return remote_port_; }
|
int GetRemotePort() { return remote_port_; }
|
||||||
@ -28,6 +30,9 @@ namespace f8
|
|||||||
void SendBuff(const char* buff, unsigned int bufflen);
|
void SendBuff(const char* buff, unsigned int bufflen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Init(std::shared_ptr<asio::io_context> io_context,
|
||||||
|
const std::string& remote_ip,
|
||||||
|
int remote_port);
|
||||||
void HandleConnect(const asio::error_code& err);
|
void HandleConnect(const asio::error_code& err);
|
||||||
void DoRead();
|
void DoRead();
|
||||||
void DoSend();
|
void DoSend();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user