@@ -28,6 +28,8 @@ void polymorph::network::tcp::Client::connect(std::function<void(bool, SessionId
2828 return ;
2929 }
3030
31+ _doReceive ();
32+
3133 ConnectionDto dto{ 0 , 0 };
3234 send<ConnectionDto>(ConnectionDto::opId, dto);
3335 _isConnecting = false ;
@@ -38,19 +40,24 @@ void polymorph::network::tcp::Client::connect(std::function<void(bool, SessionId
3840 return true ;
3941 });
4042 });
41- _doReceive ();
4243 _run ();
4344}
4445
4546void polymorph::network::tcp::Client::connectWithSession (polymorph::network::SessionId session,
4647 polymorph::network::AuthorizationKey authKey, std::function<void (bool , SessionId)> callback)
4748{
4849 _socket.async_connect (_serverEndpoint, [this , callback, session, authKey](std::error_code ec) {
50+ if (ec == asio::error::operation_aborted) {
51+ return ;
52+ }
4953 if (ec) {
5054 std::cerr << " Error while connecting to server: " << ec.message () << std::endl;
5155 callback (false , 0 );
5256 return ;
5357 }
58+
59+ _doReceive ();
60+
5461 ConnectionDto dto{ .sessionId = session, .authKey = authKey };
5562 send<ConnectionDto>(ConnectionDto::opId, dto);
5663 _isConnecting = false ;
@@ -61,7 +68,6 @@ void polymorph::network::tcp::Client::connectWithSession(polymorph::network::Ses
6168 return true ;
6269 });
6370 });
64- _doReceive ();
6571 _run ();
6672}
6773
@@ -92,7 +98,7 @@ void polymorph::network::tcp::Client::_doSend()
9298void polymorph::network::tcp::Client::_doReceive ()
9399{
94100 _socket.async_receive (asio::buffer (_internalBuffer), [this ](const asio::error_code &error, std::size_t bytesReceived) {
95- if (error == asio::error::operation_aborted)
101+ if (error == asio::error::operation_aborted || error == asio::error::eof )
96102 return ;
97103 if (error) {
98104 std::cerr << " Error while receiving packet: " << error.message () << std::endl;
0 commit comments