Skip to content

Commit

Permalink
FIX: test reading and writing socket, do not lose connection on timeout
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@6813 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed Oct 13, 2013
1 parent c465ad9 commit 5234dcc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions network/network.cc
Expand Up @@ -617,16 +617,18 @@ bool network_check_server_connection()
return false;
}

fd_set fds;
fd_set fds_read, fds_write;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&fds);
socket_list_t::fill_set(&fds);

int action = select( FD_SETSIZE, NULL, &fds, NULL, &tv );
if( action<=0 ) {
// timeout
FD_ZERO(&fds_read);
socket_list_t::fill_set(&fds_read);
FD_ZERO(&fds_write);
socket_list_t::fill_set(&fds_write);

int action = select( FD_SETSIZE, &fds_read, &fds_write, NULL, &tv );
if( action < 0 ) {
// error - connection lost
return false;
}
}
Expand Down

0 comments on commit 5234dcc

Please sign in to comment.