1
This commit is contained in:
parent
ed93a7c237
commit
77fb8a70b2
@ -26,7 +26,6 @@ namespace a8
|
||||
);
|
||||
send_buffer_mutex_ = std::make_shared<std::mutex>();
|
||||
io_context_ = std::make_shared<asio::io_context>();
|
||||
resolver_ = std::make_shared<asio::ip::tcp::resolver>(*io_context_);
|
||||
socket_ = std::make_shared<asio::ip::tcp::socket>(*io_context_);
|
||||
new std::thread(&AsioTcpClient::WorkerThreadProc, this);
|
||||
}
|
||||
@ -98,15 +97,12 @@ namespace a8
|
||||
{
|
||||
actived_ = true;
|
||||
connected_ = false;
|
||||
|
||||
#if 0
|
||||
asio::async_connect(*socket_, endpoints,
|
||||
[this] (const asio::error_code& ec,
|
||||
const tcp::endpoint& endpoint)
|
||||
{
|
||||
HandleConnect(ec, endpoint);
|
||||
});
|
||||
#endif
|
||||
socket_->async_connect
|
||||
(*endpoint_,
|
||||
[this] (const asio::error_code& ec)
|
||||
{
|
||||
HandleConnect(ec);
|
||||
});
|
||||
}
|
||||
|
||||
void AsioTcpClient::ActiveStop()
|
||||
@ -115,7 +111,7 @@ namespace a8
|
||||
connected_ = false;
|
||||
}
|
||||
|
||||
void AsioTcpClient::HandleConnect(const asio::error_code& err, const tcp::endpoint& endpoint)
|
||||
void AsioTcpClient::HandleConnect(const asio::error_code& err)
|
||||
{
|
||||
if (err) {
|
||||
actived_ = false;
|
||||
@ -193,6 +189,7 @@ namespace a8
|
||||
while (true) {
|
||||
try {
|
||||
io_context_->run();
|
||||
io_context_->reset();
|
||||
int i = 0;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "Exception: " << e.what() << "\n";
|
||||
|
@ -28,7 +28,7 @@ namespace a8
|
||||
void SendBuff(const char* buff, unsigned int bufflen);
|
||||
|
||||
private:
|
||||
void HandleConnect(const asio::error_code& err, const tcp::endpoint& endpoint);
|
||||
void HandleConnect(const asio::error_code& err);
|
||||
void DoRead();
|
||||
void DoSend();
|
||||
void WorkerThreadProc();
|
||||
@ -39,7 +39,6 @@ namespace a8
|
||||
|
||||
std::shared_ptr<asio::ip::tcp::endpoint> endpoint_;
|
||||
std::shared_ptr<asio::io_context> io_context_;
|
||||
std::shared_ptr<asio::ip::tcp::resolver> resolver_;
|
||||
std::shared_ptr<asio::ip::tcp::socket> socket_;
|
||||
volatile bool actived_ = false;
|
||||
volatile bool connected_ = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user