Set a timeout on the lobby client to prevent blocking on connections to the lobby

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7095 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2009-04-20 13:27:07 +00:00 committed by Git SVN Gateway
parent 846a21b8a7
commit 5694b99b90
1 changed files with 20 additions and 16 deletions

View File

@ -49,11 +49,13 @@ class masterserver_connection:
def list(self):
with _socket(socket.AF_INET, socket.SOCK_STREAM) as s:
games = []
try:
s.settimeout(10)
s.connect( (self.host, self.port) )
self._send(s, "list")
self._send(s, "list\0")
(count,) = self._recv(s, "!I")
games = []
for i in xrange(0,count):
(description, size, flags, host, maxPlayers, currentPlayers,
user1, user2, user3, user4 ) = self._recv(s, "!64sII16sIIIIII")
@ -66,6 +68,8 @@ class masterserver_connection:
currentPlayers = _swap_endianness(currentPlayers)
g = game(description, host, maxPlayers, currentPlayers)
games.append(g)
except socket.timeout:
pass
return games