mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-10 17:50:48 +00:00
* net_sdlnet.c: Added ASSERT_SOCKETID for paranoid debugging purposes,
disabled by default. Made socket_id() to work in two passes, once for looking for a match and the next for looking for an empty slot in the net_sockets[] array. Made it to Sys_Error if there are no empty slots. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@197 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
9940a1ef02
commit
c026da1140
1 changed files with 24 additions and 15 deletions
|
@ -35,6 +35,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#define MAX_SOCKETS 32
|
#define MAX_SOCKETS 32
|
||||||
|
|
||||||
|
#if 0 /* enable for paranoid debugging purposes */
|
||||||
|
#define ASSERT_SOCKETID(s) \
|
||||||
|
do { \
|
||||||
|
if ((s) < 0 || (s) >= MAX_SOCKETS) \
|
||||||
|
Sys_Error("Bad socket ID %d at line %d",(s),__LINE__); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define ASSERT_SOCKETID(s) do {} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
static int net_controlsocket;
|
static int net_controlsocket;
|
||||||
static int net_broadcastsocket = 0;
|
static int net_broadcastsocket = 0;
|
||||||
static int net_acceptsocket = -1;
|
static int net_acceptsocket = -1;
|
||||||
|
@ -47,25 +57,22 @@ UDPsocket net_sockets[MAX_SOCKETS];
|
||||||
|
|
||||||
static int socket_id (UDPsocket socket_p)
|
static int socket_id (UDPsocket socket_p)
|
||||||
{
|
{
|
||||||
int i;
|
int idx;
|
||||||
int idx = -1;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_SOCKETS; i++)
|
for (idx = 0; idx < MAX_SOCKETS; idx++)
|
||||||
{
|
{
|
||||||
if (net_sockets[i] == socket_p)
|
if (net_sockets[idx] == socket_p)
|
||||||
return i;
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
if (net_sockets[i] == NULL && idx == -1)
|
for (idx = 0; idx < MAX_SOCKETS; idx++)
|
||||||
{
|
{
|
||||||
idx = i;
|
if (net_sockets[idx] == NULL)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == MAX_SOCKETS)
|
||||||
{
|
Sys_Error("net_sdlnet: No free sockets.");
|
||||||
// todo error
|
|
||||||
}
|
|
||||||
|
|
||||||
net_sockets[idx] = socket_p;
|
net_sockets[idx] = socket_p;
|
||||||
|
|
||||||
|
@ -219,7 +226,7 @@ int SDLN_CloseSocket (int socketid)
|
||||||
|
|
||||||
if (socketid == net_broadcastsocket)
|
if (socketid == net_broadcastsocket)
|
||||||
net_broadcastsocket = -1;
|
net_broadcastsocket = -1;
|
||||||
|
ASSERT_SOCKETID(socketid);
|
||||||
socket_p = net_sockets[socketid];
|
socket_p = net_sockets[socketid];
|
||||||
|
|
||||||
if (socket_p == NULL)
|
if (socket_p == NULL)
|
||||||
|
@ -265,6 +272,7 @@ int SDLN_Read (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||||
IPaddress *ipaddress;
|
IPaddress *ipaddress;
|
||||||
UDPsocket socket_p;
|
UDPsocket socket_p;
|
||||||
|
|
||||||
|
ASSERT_SOCKETID(socketid);
|
||||||
socket_p = net_sockets[socketid];
|
socket_p = net_sockets[socketid];
|
||||||
if (socket_p == NULL)
|
if (socket_p == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -294,6 +302,7 @@ int SDLN_Write (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||||
UDPsocket socket_p;
|
UDPsocket socket_p;
|
||||||
IPaddress *ipaddress;
|
IPaddress *ipaddress;
|
||||||
|
|
||||||
|
ASSERT_SOCKETID(socketid);
|
||||||
socket_p = net_sockets[socketid];
|
socket_p = net_sockets[socketid];
|
||||||
if (socket_p == NULL)
|
if (socket_p == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -366,7 +375,7 @@ int SDLN_GetSocketAddr (int socketid, struct qsockaddr *addr)
|
||||||
IPaddress *ipaddress;
|
IPaddress *ipaddress;
|
||||||
|
|
||||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||||
|
ASSERT_SOCKETID(socketid);
|
||||||
socket_p = net_sockets[socketid];
|
socket_p = net_sockets[socketid];
|
||||||
if (socket_p == NULL)
|
if (socket_p == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue