diff --git a/Source/SocketIOLib/Private/internal/sio_client_impl.cpp b/Source/SocketIOLib/Private/internal/sio_client_impl.cpp index 5a14879f..634f364d 100644 --- a/Source/SocketIOLib/Private/internal/sio_client_impl.cpp +++ b/Source/SocketIOLib/Private/internal/sio_client_impl.cpp @@ -165,8 +165,8 @@ namespace sio void client_impl::close() { //don't ever try to close with multiple reconnect attempts - m_reconn_attempts_when_closed = m_reconn_attempts; - this->set_reconnect_attempts(0); + //m_reconn_attempts_when_closed = m_reconn_attempts; + //this->set_reconnect_attempts(0); m_con_state = con_closing; this->sockets_invoke_void(&sio::socket::close); @@ -176,9 +176,6 @@ namespace sio void client_impl::sync_close() { - m_reconn_attempts_when_closed = m_reconn_attempts; - this->set_reconnect_attempts(0); - this->close(); if(m_network_thread) { @@ -274,7 +271,7 @@ namespace sio void client_impl::close_impl(close::status::value const& code,string const& reason) { - LOG("Close by reason: %d" << reason << endl); + UE_LOG(LogTemp, Log, TEXT("Close by reason: %s"), *FString(reason.c_str())); if(m_reconn_timer) { m_reconn_timer->cancel(); @@ -282,7 +279,7 @@ namespace sio } if (m_con.expired()) { - cerr << "Error: No active session" << endl; + UE_LOG(LogTemp, Warning, TEXT("close_impl::Error: No active session: %s"), *FString(reason.c_str())); } else { @@ -304,7 +301,7 @@ namespace sio m_client.send(m_con,*payload_ptr,opcode,ec); if(ec) { - cerr<<"Send failed,reason:"<< ec.message()<expires_from_now(std::chrono::milliseconds(m_ping_interval), e_code); m_ping_timer->async_wait(lib::bind(&client_impl::ping,this,lib::placeholders::_1)); + UE_LOG(LogTemp, Log, TEXT("Starting ping timeout 1")); } - if(!m_ping_timeout_timer) + if (!m_ping_timeout_timer) { m_ping_timeout_timer.reset(new asio::system_timer(m_client.get_io_service())); - lib::error_code timeout_ec; - m_ping_timeout_timer->expires_from_now(std::chrono::milliseconds(m_ping_timeout), timeout_ec); - m_ping_timeout_timer->async_wait(lib::bind(&client_impl::timeout_pong, this,lib::placeholders::_1)); } + lib::error_code timeout_ec; + m_ping_timeout_timer->expires_from_now(std::chrono::milliseconds(m_ping_timeout), timeout_ec); + m_ping_timeout_timer->async_wait(lib::bind(&client_impl::timeout_pong, this,lib::placeholders::_1)); + UE_LOG(LogTemp, Log, TEXT("Starting m_ping_timeout_timer timeout 1")); } void client_impl::timeout_pong(const lib::error_code &ec) { if(ec) { + if (ec != asio::error::operation_aborted) + { + UE_LOG(LogTemp, Log, TEXT("timeout_pong err: %d"), ec.value()); + } return; } - LOG("Pong timeout"< closing connection")); - m_client.get_io_service().dispatch(lib::bind(&client_impl::close_impl, this,close::status::policy_violation,"Pong timeout")); + m_client.get_io_service().dispatch(lib::bind(&client_impl::close_impl, this, close::status::policy_violation,"Pong timeout")); } void client_impl::timeout_reconnect(lib::error_code const& ec) @@ -362,9 +364,9 @@ namespace sio m_con_state = con_opening; m_reconn_made++; this->reset_states(); - LOG("Reconnecting..."<sockets_invoke_void(&sio::socket::on_disconnect); - LOG("Connection failed." << endl); + UE_LOG(LogTemp, Log, TEXT("Connection failed.")); if(m_reconn_madenext_delay(); if(m_reconnect_listener) m_reconnect_listener(m_reconn_made,delay); m_reconn_timer.reset(new asio::system_timer(m_client.get_io_service())); @@ -425,7 +427,7 @@ namespace sio void client_impl::on_open(connection_hdl con) { - LOG("Connected." << endl); + UE_LOG(LogTemp, Log, TEXT("Connected.")); m_con_state = con_opened; m_con = con; @@ -442,13 +444,13 @@ namespace sio void client_impl::on_close(connection_hdl con) { - LOG("Client Disconnected." << endl); + UE_LOG(LogTemp, Log, TEXT("Client Disconnected.")); m_con_state = con_closed; lib::error_code ec; close::status::value code = close::status::normal; client_type::connection_ptr conn_ptr = m_client.get_con_from_hdl(con, ec); if (ec) { - LOG("OnClose get conn failed"<sockets_invoke_void(&sio::socket::on_disconnect); if(m_reconn_madenext_delay(); if(m_reconnect_listener) m_reconnect_listener(m_reconn_made,delay); m_reconn_timer.reset(new asio::system_timer(m_client.get_io_service())); @@ -492,6 +494,7 @@ namespace sio lib::error_code ec; m_ping_timeout_timer->expires_from_now(std::chrono::milliseconds(m_ping_timeout),ec); m_ping_timeout_timer->async_wait(lib::bind(&client_impl::timeout_pong, this, lib::placeholders::_1)); + UE_LOG(LogTemp, Log, TEXT("Resetting m_ping_timeout_timer timeout from on_message")); } // Parse the incoming message according to socket.IO rules m_packet_mgr.put_payload(msg->get_payload()); @@ -519,6 +522,9 @@ namespace sio { m_ping_interval = 25000; } + //temp debug modification + //m_ping_interval = 5000; + it = values->find("pingTimeout"); if (it!=values->end()&&it->second->get_flag() == message::flag_integer) { @@ -533,10 +539,12 @@ namespace sio lib::error_code ec; m_ping_timer->expires_from_now(std::chrono::milliseconds(m_ping_interval), ec); if (ec) { - //LOG("ec:" << ec.message() << endl); + UE_LOG(LogTemp, Log, TEXT("ec: %s"), ec.message().c_str()); } + UE_LOG(LogTemp, Log, TEXT("Started ping timeout due to on_handshake")); + m_ping_timer->async_wait(lib::bind(&client_impl::ping,this,lib::placeholders::_1)); - LOG("On handshake,sid:"<cancel(); m_ping_timeout_timer.reset(); + UE_LOG(LogTemp, Log, TEXT("m_ping_timeout_timer cancelled by on_pong")); } } @@ -582,22 +592,24 @@ namespace sio void client_impl::on_encode(bool isBinary,shared_ptr const& payload) { LOG("encoded payload length:"<length()<cancel(ec); m_ping_timeout_timer.reset(); + UE_LOG(LogTemp, Log, TEXT("m_ping_timeout_timer cleared: %d"), ec.value()); } if(m_ping_timer) { m_ping_timer->cancel(ec); m_ping_timer.reset(); + UE_LOG(LogTemp, Log, TEXT("m_ping_timer cleared: %d"), ec.value()); } } @@ -624,4 +636,4 @@ namespace sio return ctx; } #endif -} +} \ No newline at end of file diff --git a/Source/SocketIOLib/Private/internal/sio_packet.cpp b/Source/SocketIOLib/Private/internal/sio_packet.cpp index 313d1a43..384fb893 100644 --- a/Source/SocketIOLib/Private/internal/sio_packet.cpp +++ b/Source/SocketIOLib/Private/internal/sio_packet.cpp @@ -507,7 +507,7 @@ namespace sio } else { - return; + break;//return; } } else if(packet::is_binary_message(payload)) @@ -524,8 +524,9 @@ namespace sio else { p.reset(new packet()); - if (!p->parse(payload)) - return; + p->parse(payload); + /*if (!p->parse(payload)) + return;*/ break; } return; diff --git a/Source/SocketIOLib/Private/sio_socket.cpp b/Source/SocketIOLib/Private/sio_socket.cpp index 508462f0..5817567d 100644 --- a/Source/SocketIOLib/Private/sio_socket.cpp +++ b/Source/SocketIOLib/Private/sio_socket.cpp @@ -299,10 +299,11 @@ namespace sio packet p(packet::type_disconnect,m_nsp); send_packet(p); - //if(!m_connection_timer) - //{ - m_connection_timer.reset(new asio::system_timer(m_client->get_io_service())); - //} + if(!m_connection_timer) + { + m_connection_timer.reset(new asio::system_timer(m_client->get_io_service())); + } + lib::error_code ec; m_connection_timer->expires_from_now(std::chrono::milliseconds(3000), ec); m_connection_timer->async_wait(lib::bind(&socket::impl::on_close, this));