partialy fix bug #10967

* Fixed networking not to timeout with slow connections but timeout
  faster with lost connection

* Fixed client side ping timeout check if downloading or uploading
This commit is contained in:
Pauli Nieminen 2008-02-04 11:38:48 +00:00
parent 92e4a75253
commit 01c14f221a
4 changed files with 19 additions and 6 deletions

View file

@ -22,6 +22,9 @@ Version 1.3.15+svn:
* During ai moves the source hex is no longer highlighted.
* show unit standing animations and idle animations are now separate options
* miscellaneous and bug fixes:
* Fixed networking not to timeout with slow connections but timeout faster
with lost connection (partialy fix bug #10967)
* Fixed client side ping timeout check if downloading or uploading
* Moved destruction of conditional object before the mutex. This should
fix random crash in network disconnect.
* Fixed reference to invalid pointer in attack::attack

View file

@ -665,15 +665,22 @@ connection receive_data(config& cfg, connection connection_num)
}
}
TCPsocket sock = connection_num == 0 ? 0 : get_socket(connection_num);
TCPsocket s = sock;
sock = network_worker_pool::get_received_data(sock,cfg);
if (sock == NULL) {
if (last_ping != 0 && ping_timeout != 0 && !is_server()
&& !network_worker_pool::is_locked(s))
if (!is_server() && last_ping != 0 && ping_timeout != 0)
{
if (connection_num == 0)
{
s = get_socket(sockets.back());
}
if (!network_work_pool::is_locked(s))
{
check_timeout();
}
}
return 0;
}

View file

@ -169,7 +169,7 @@ int receive_bytes(TCPsocket s, char* buf, size_t nbytes)
}
bool receive_with_timeout(TCPsocket s, char* buf, size_t nbytes,
bool update_stats=false, int timeout_ms=60000)
bool update_stats=false, int timeout_ms=10000)
{
int startTicks = SDL_GetTicks();
int time_used = 0;
@ -234,6 +234,8 @@ bool receive_with_timeout(TCPsocket s, char* buf, size_t nbytes,
return false;
}
nbytes -= bytes_read;
// We got some data from server so reset start time so slow conenction won't timeout.
startTicks = SDL_GetTicks();
}
}
@ -264,6 +266,7 @@ static SOCKET_STATE send_buffer(TCPsocket sock, config& config_in, const bool gz
SDLNet_Write32(value.size()+1,&buf[0]);
std::copy(value.begin(),value.end(),buf.begin()+4);
buf.back() = 0;
size_t size = buf.size();
{
const threading::lock lock(*stats_mutex);

View file

@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE( test_send_client )
BOOST_CHECK_MESSAGE( receive_from == server_client1, "Received data is not from test client 1" );
BOOST_CHECK_MESSAGE(cfg_send == received, "send is not same as received\n" << cfg_send << "\n" << received.debug() );
BOOST_CHECK_EQUAL(cfg_send, received);
}