From f03e4565ad64b6e529fc4497e2b41989f350d667 Mon Sep 17 00:00:00 2001 From: zuo000 Date: Mon, 19 Dec 2022 13:32:59 +0800 Subject: [PATCH] fix a bug the bug is that send buffer will be reset in sync mode when the main thread is watching _connected flag --- source/server/asio/tcp_client.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/server/asio/tcp_client.cpp b/source/server/asio/tcp_client.cpp index d121b329..e8fc2610 100644 --- a/source/server/asio/tcp_client.cpp +++ b/source/server/asio/tcp_client.cpp @@ -317,14 +317,14 @@ bool TCPClient::ConnectAsync() _bytes_sent = 0; _bytes_received = 0; + // Call the client connected handler, onConnected will reset FBE buffers, so it could not be located after _connected flag changed + onConnected(); + // Update the connected flag _connected = true; // Try to receive something from the server - TryReceive(); - - // Call the client connected handler - onConnected(); + TryReceive(); // Call the empty send buffer handler if (_send_buffer_main.empty()) @@ -409,16 +409,16 @@ bool TCPClient::ConnectAsync(const std::shared_ptr& resolver) _bytes_sending = 0; _bytes_sent = 0; _bytes_received = 0; - + + // Call the client connected handler, onConnected will reset FBE buffers, so it could not be located after _connected flag changed + onConnected(); + // Update the connected flag _connected = true; // Try to receive something from the server TryReceive(); - // Call the client connected handler - onConnected(); - // Call the empty send buffer handler if (_send_buffer_main.empty()) onEmpty();