NetPlay refactoring:

* Rename addSocket to more descriptive SocketSet_AddSocket
 * Rename delSocket to more descriptive SocketSet_DelSocket

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9952 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2010-02-21 20:26:27 +00:00 committed by Git SVN Gateway
parent 401723958c
commit 2c09022412
1 changed files with 23 additions and 23 deletions

View File

@ -611,7 +611,7 @@ static SocketSet* allocSocketSet(size_t count)
* *
* @return true if @c socket is succesfully added to @set. * @return true if @c socket is succesfully added to @set.
*/ */
static bool addSocket(SocketSet* set, Socket* socket) static bool SocketSet_AddSocket(SocketSet* set, Socket* socket)
{ {
size_t i; size_t i;
@ -644,7 +644,7 @@ static bool addSocket(SocketSet* set, Socket* socket)
/** /**
* Remove the given socket from the given socket set. * Remove the given socket from the given socket set.
*/ */
static void delSocket(SocketSet* set, Socket* socket) static void SocketSet_DelSocket(SocketSet* set, Socket* socket)
{ {
size_t i; size_t i;
@ -1328,7 +1328,7 @@ static BOOL NET_fillBuffer(NETBUFSOCKET* bs, SocketSet* socket_set)
// an error occured, or the remote host has closed the connection. // an error occured, or the remote host has closed the connection.
if (socket_set != NULL) if (socket_set != NULL)
{ {
delSocket(socket_set, bs->socket); SocketSet_DelSocket(socket_set, bs->socket);
} }
ASSERT(bs->bytes < NET_BUFFER_SIZE, "Socket buffer is too small!"); ASSERT(bs->bytes < NET_BUFFER_SIZE, "Socket buffer is too small!");
@ -1509,7 +1509,7 @@ static void NETplayerClientDisconnect(uint32_t index)
index, connected_bsocket[index]->socket); index, connected_bsocket[index]->socket);
// Although we can get a error result from DelSocket, it don't really matter here. // Although we can get a error result from DelSocket, it don't really matter here.
delSocket(socket_set, connected_bsocket[index]->socket); SocketSet_DelSocket(socket_set, connected_bsocket[index]->socket);
socketClose(connected_bsocket[index]->socket); socketClose(connected_bsocket[index]->socket);
connected_bsocket[index]->socket = NULL; connected_bsocket[index]->socket = NULL;
NetPlay.players[index].heartbeat = false; NetPlay.players[index].heartbeat = false;
@ -1539,7 +1539,7 @@ static void NETplayerLeaving(UDWORD index)
index, connected_bsocket[index]->socket); index, connected_bsocket[index]->socket);
// Although we can get a error result from DelSocket, it don't really matter here. // Although we can get a error result from DelSocket, it don't really matter here.
delSocket(socket_set, connected_bsocket[index]->socket); SocketSet_DelSocket(socket_set, connected_bsocket[index]->socket);
socketClose(connected_bsocket[index]->socket); socketClose(connected_bsocket[index]->socket);
connected_bsocket[index]->socket = NULL; connected_bsocket[index]->socket = NULL;
} }
@ -2126,7 +2126,7 @@ int NETclose(void)
allow_joining = false; allow_joining = false;
if(bsocket) if(bsocket)
{ // need delSocket() as well, socket_set or tmp_socket_set? { // need SocketSet_DelSocket() as well, socket_set or tmp_socket_set?
debug(LOG_NET, "Closing bsocket %p socket %p (tcp_socket=%p)", bsocket, bsocket->socket, tcp_socket); debug(LOG_NET, "Closing bsocket %p socket %p (tcp_socket=%p)", bsocket, bsocket->socket, tcp_socket);
//socketClose(bsocket->socket); //socketClose(bsocket->socket);
NET_destroyBufferedSocket(bsocket); NET_destroyBufferedSocket(bsocket);
@ -2159,7 +2159,7 @@ int NETclose(void)
{ {
if (tmp_socket[i]) if (tmp_socket[i])
{ {
// FIXME: need delSocket() as well, socket_set or tmp_socket_set? // FIXME: need SocketSet_DelSocket() as well, socket_set or tmp_socket_set?
debug(LOG_NET, "Closing tmp_socket[%d] %p", i, tmp_socket[i]); debug(LOG_NET, "Closing tmp_socket[%d] %p", i, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i]=NULL; tmp_socket[i]=NULL;
@ -2171,7 +2171,7 @@ int NETclose(void)
// checking to make sure tcp_socket is still valid // checking to make sure tcp_socket is still valid
if (tcp_socket) if (tcp_socket)
{ {
delSocket(socket_set, tcp_socket); SocketSet_DelSocket(socket_set, tcp_socket);
} }
debug(LOG_NET, "Freeing socket_set %p", socket_set); debug(LOG_NET, "Freeing socket_set %p", socket_set);
free(socket_set); free(socket_set);
@ -3179,7 +3179,7 @@ static void NETallowJoining(void)
if (tmp_socket[i] == NULL // Make sure that we're not out of sockets if (tmp_socket[i] == NULL // Make sure that we're not out of sockets
&& (tmp_socket[i] = socketAccept(tcp_socket)) != NULL) && (tmp_socket[i] = socketAccept(tcp_socket)) != NULL)
{ {
addSocket(tmp_socket_set, tmp_socket[i]); SocketSet_AddSocket(tmp_socket_set, tmp_socket[i]);
if (checkSockets(tmp_socket_set, NET_TIMEOUT_DELAY) > 0 if (checkSockets(tmp_socket_set, NET_TIMEOUT_DELAY) > 0
&& tmp_socket[i]->ready && tmp_socket[i]->ready
&& (recv_result = readNoInt(tmp_socket[i], buffer, 5)) && (recv_result = readNoInt(tmp_socket[i], buffer, 5))
@ -3202,7 +3202,7 @@ static void NETallowJoining(void)
NETsendGAMESTRUCT(tmp_socket[i], &gamestruct); NETsendGAMESTRUCT(tmp_socket[i], &gamestruct);
} }
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
} }
@ -3212,21 +3212,21 @@ static void NETallowJoining(void)
if (!NETsendGAMESTRUCT(tmp_socket[i], &gamestruct)) if (!NETsendGAMESTRUCT(tmp_socket[i], &gamestruct))
{ {
debug(LOG_ERROR, "Failed to respond (with GAMESTRUCT) to 'join' command: %s", strSockError(getSockErr())); debug(LOG_ERROR, "Failed to respond (with GAMESTRUCT) to 'join' command: %s", strSockError(getSockErr()));
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
} }
} }
else else
{ {
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
} }
} }
else else
{ {
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
} }
@ -3253,7 +3253,7 @@ static void NETallowJoining(void)
debug(LOG_NET, "Client socket ecountered error: %s", strSockError(getSockErr())); debug(LOG_NET, "Client socket ecountered error: %s", strSockError(getSockErr()));
} }
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
} }
@ -3284,15 +3284,15 @@ static void NETallowJoining(void)
if (index == -1) if (index == -1)
{ {
// FIXME: No room. Dropping the player without warning since protocol doesn't seem to support rejection at this point // FIXME: No room. Dropping the player without warning since protocol doesn't seem to support rejection at this point
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
socketClose(tmp_socket[i]); socketClose(tmp_socket[i]);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
return; return;
} }
delSocket(tmp_socket_set, tmp_socket[i]); SocketSet_DelSocket(tmp_socket_set, tmp_socket[i]);
NET_initBufferedSocket(connected_bsocket[index], tmp_socket[i]); NET_initBufferedSocket(connected_bsocket[index], tmp_socket[i]);
addSocket(socket_set, connected_bsocket[index]->socket); SocketSet_AddSocket(socket_set, connected_bsocket[index]->socket);
tmp_socket[i] = NULL; tmp_socket[i] = NULL;
if (!NETisCorrectVersion(MajorVersion, MinorVersion)) if (!NETisCorrectVersion(MajorVersion, MinorVersion))
@ -3326,7 +3326,7 @@ static void NETallowJoining(void)
NET_DestroyPlayer(index); NET_DestroyPlayer(index);
allow_joining = true; allow_joining = true;
delSocket(socket_set, connected_bsocket[index]->socket); SocketSet_DelSocket(socket_set, connected_bsocket[index]->socket);
socketClose(connected_bsocket[index]->socket); socketClose(connected_bsocket[index]->socket);
connected_bsocket[index]->socket = NULL; connected_bsocket[index]->socket = NULL;
return; return;
@ -3549,7 +3549,7 @@ BOOL NETfindGame(void)
if (tcp_socket != NULL) if (tcp_socket != NULL)
{ {
debug(LOG_NET, "Deleting tcp_socket %p", tcp_socket); debug(LOG_NET, "Deleting tcp_socket %p", tcp_socket);
delSocket(socket_set,tcp_socket); SocketSet_DelSocket(socket_set,tcp_socket);
socketClose(tcp_socket); socketClose(tcp_socket);
tcp_socket = NULL; tcp_socket = NULL;
} }
@ -3580,7 +3580,7 @@ BOOL NETfindGame(void)
} }
debug(LOG_NET, "Created socket_set %p", socket_set); debug(LOG_NET, "Created socket_set %p", socket_set);
addSocket(socket_set, tcp_socket); SocketSet_AddSocket(socket_set, tcp_socket);
debug(LOG_NET, "Sending list cmd"); debug(LOG_NET, "Sending list cmd");
@ -3712,13 +3712,13 @@ connect_succesfull:
debug(LOG_NET, "Created socket_set %p", socket_set); debug(LOG_NET, "Created socket_set %p", socket_set);
// tcp_socket is used to talk to host machine // tcp_socket is used to talk to host machine
addSocket(socket_set, tcp_socket); SocketSet_AddSocket(socket_set, tcp_socket);
if (writeAll(tcp_socket, "join", sizeof("join")) == SOCKET_ERROR) if (writeAll(tcp_socket, "join", sizeof("join")) == SOCKET_ERROR)
{ {
debug(LOG_ERROR, "Failed to send 'join' command: %s", strSockError(getSockErr())); debug(LOG_ERROR, "Failed to send 'join' command: %s", strSockError(getSockErr()));
freeaddrinfo(hosts); freeaddrinfo(hosts);
delSocket(socket_set, tcp_socket); SocketSet_DelSocket(socket_set, tcp_socket);
socketClose(tcp_socket); socketClose(tcp_socket);
free(socket_set); free(socket_set);
socket_set = NULL; socket_set = NULL;
@ -3734,7 +3734,7 @@ connect_succesfull:
if (NetPlay.games[gameNumber].desc.dwCurrentPlayers >= NetPlay.games[gameNumber].desc.dwMaxPlayers) if (NetPlay.games[gameNumber].desc.dwCurrentPlayers >= NetPlay.games[gameNumber].desc.dwMaxPlayers)
{ {
// Shouldn't join; game is full // Shouldn't join; game is full
delSocket(socket_set, tcp_socket); SocketSet_DelSocket(socket_set, tcp_socket);
socketClose(tcp_socket); socketClose(tcp_socket);
free(socket_set); free(socket_set);
socket_set = NULL; socket_set = NULL;