[crossfire] GTK-V2 init_connection() change.

Kevin Bulgrien kbulgrien at att.net
Wed Apr 28 02:20:12 CDT 2010


This took me way out of my comfort zone, but in trying to fix another bug
in the client, I experienced several really hard lockups that traced down to
the connect() call inside init_connection() found in common/client.c.  The
lockup lasted 3 minutes before the client came back.  During this time the
client UI was completely unresponsive (white screen).  I have also gotten
into this situation a number of times when the metaserver went down, and I
find it really annoying.

When I commented about this on IRC, the suggestion was made to consider
multi-threading the client as a solution.  I know I'm not up to that yet, but,
what I found out was that the connection attempts are made in blocking mode.
After some research, I found out how to implement a timeout by temporarily
configuring the socket in non-blocking mode during the connection.

I made a change to the existing code to block no longer than 30 seconds.  It
was tempting to put in a shorter timeout, but then I remembered that a DNS
lookup failure can take about 30 seconds, so at least for now I went with
30 seconds as it is significantly better than 3 minutes.

I made no attempt to modify code that did not run on my system, so the case
where !HAVE_GETADDRINFO || WIN32 has not been modified.  It seems that it
might be possible to refactor the code a tiny bit to make it possible to
implement in that case without having to copy/paste the changes.

The code changes could bear some testing on other systems, though I suspect
the changes are not problematic for different platforms.

I did not skimp on the error reporting, and implemented various checks that
I saw while researching how to implement non-blocking connection attempts.
It's probably kind of in-depth for a game client, but...

The commit is 13015.  If this change causes to much trouble, that is the only
change made in the commit, so it should be easy to revert if need be.

Kevin Bulgrien



More information about the crossfire mailing list