[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src network_worker.cpp
From: |
Jon Daniel |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src network_worker.cpp |
Date: |
Fri, 05 Aug 2005 09:00:59 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Jon Daniel <address@hidden> 05/08/05 13:00:58
Modified files:
src : network_worker.cpp
Log message:
Fix receive_buf to receive only one byte at a time so we can check with
timeout if there was an error
timeout should be 15s now.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network_worker.cpp.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
Patches:
Index: wesnoth/src/network_worker.cpp
diff -u wesnoth/src/network_worker.cpp:1.35 wesnoth/src/network_worker.cpp:1.36
--- wesnoth/src/network_worker.cpp:1.35 Thu Aug 4 22:47:58 2005
+++ wesnoth/src/network_worker.cpp Fri Aug 5 13:00:58 2005
@@ -1,4 +1,4 @@
-/* $Id: network_worker.cpp,v 1.35 2005/08/04 22:47:58 j_daniel Exp $ */
+/* $Id: network_worker.cpp,v 1.36 2005/08/05 13:00:58 j_daniel Exp $ */
/*
Copyright (C) 2003-5 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -27,7 +27,7 @@
#include <vector>
#define LOG_NW LOG_STREAM(info, network)
-
+#define ERR_NW LOG_STREAM(err, network)
namespace {
unsigned int buf_id = 0;
@@ -92,16 +92,31 @@
SOCKET_STATE receive_buf(TCPsocket sock, std::vector<char>& buf)
{
+ SDLNet_SocketSet set = SDLNet_AllocSocketSet(1);
+ if(!set) {
+ ERR_NW << "SDLNet_AllocSocketSet: " << SDLNet_GetError() <<
"\n";
+ SDLNet_FreeSocketSet(set);
+ return SOCKET_ERROR;
+ }
+ if(SDLNet_TCP_AddSocket(set, sock) < 0) {
+ ERR_NW << "SDLNet_TCP_AddSocket: " << SDLNet_GetError() << "\n";
+ SDLNet_FreeSocketSet(set);
+ return SOCKET_ERROR;
+ }
char num_buf[4];
int len = SDLNet_TCP_Recv(sock,num_buf,4);
if(len != 4) {
+ SDLNet_TCP_DelSocket(set, sock);
+ SDLNet_FreeSocketSet(set);
return SOCKET_ERROR;
}
len = SDLNet_Read32(num_buf);
if(len < 1 || len > 100000000) {
+ SDLNet_TCP_DelSocket(set, sock);
+ SDLNet_FreeSocketSet(set);
return SOCKET_ERROR;
}
@@ -117,11 +132,24 @@
// if we are receiving the socket is in sockets_locked
// check if it is still locked
const threading::lock lock(*global_mutex);
- if(sockets_locked[sock] != SOCKET_LOCKED)
+ if(sockets_locked[sock] != SOCKET_LOCKED) {
+ SDLNet_TCP_DelSocket(set, sock);
+ SDLNet_FreeSocketSet(set);
return SOCKET_ERROR;
+ }
+ }
+ // check for a maximum of 15 seconds for the socket to have a
activity
+ if(SDLNet_CheckSockets(set, 15000) <= 0) {
+ ERR_NW << "SDLNet_CheckSockets: " << SDLNet_GetError()
<< "\n";
+ SDLNet_TCP_DelSocket(set, sock);
+ SDLNet_FreeSocketSet(set);
+ return SOCKET_ERROR;
}
- const int len = SDLNet_TCP_Recv(sock,beg,end - beg);
+ // receive one byte at a time
+ const int len = SDLNet_TCP_Recv(sock,beg, 1);
if(len <= 0) {
+ SDLNet_TCP_DelSocket(set, sock);
+ SDLNet_FreeSocketSet(set);
return SOCKET_ERROR;
}
@@ -129,7 +157,8 @@
current_transfer_stats.first = beg - &buf[0];
}
-
+ SDLNet_TCP_DelSocket(set, sock);
+ SDLNet_FreeSocketSet(set);
return SOCKET_READY;
}
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/04
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/04
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/04
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp,
Jon Daniel <=
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/05
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/05
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/06
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/07
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/18
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/19