Updated SDL_net

This commit is contained in:
pelya
2012-03-01 12:31:51 +02:00
parent c0482e36e2
commit 6d88235cf4
9 changed files with 410 additions and 1988 deletions

View File

@@ -1,26 +1,25 @@
/*
SDL_net: An example cross-platform network library for use with SDL
Copyright (C) 1997-2004 Sam Lantinga
SDL_net: An example cross-platform network library for use with SDL
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* $Id: SDLnetselect.c 1192 2004-01-04 17:41:55Z slouken $ */
/* $Id$ */
#include "SDLnetsys.h"
#include "SDL_net.h"
@@ -30,9 +29,6 @@
struct SDLNet_Socket {
int ready;
SOCKET channel;
#ifdef MACOS_OPENTRANSPORT
OTEventCode curEvent;
#endif
};
struct _SDLNet_SocketSet {
@@ -111,64 +107,6 @@ int SDLNet_DelSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock)
first. This function returns the number of sockets ready for reading,
or -1 if there was an error with the select() system call.
*/
#ifdef MACOS_OPENTRANSPORT
int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
{
Uint32 stop;
int numReady;
/* Loop, polling the network devices */
stop = SDL_GetTicks() + timeout;
do
{
OTResult status;
size_t numBytes;
int i;
numReady = 0;
for (i = set->numsockets-1;i >= 0;--i)
{
status = OTLook( set->sockets[i]->channel );
if( status > 0 )
{
switch( status )
{
case T_UDERR:
OTRcvUDErr( set->sockets[i]->channel , nil);
break;
case T_DISCONNECT:
OTRcvDisconnect( set->sockets[i]->channel, nil );
break;
case T_ORDREL:
OTRcvOrderlyDisconnect(set->sockets[i]->channel );
break;
case T_CONNECT:
OTRcvConnect( set->sockets[i]->channel, nil );
break;
default:
set->sockets[i]->ready = 1;
++numReady;
}
}
else if( OTCountDataBytes(set->sockets[i]->channel, &numBytes ) != kOTNoDataErr )
{
set->sockets[i]->ready = 1;
++numReady;
}
else
set->sockets[i]->ready = 0;
}
} while (!numReady && (SDL_GetTicks() < stop));
return(numReady);
}
#else
int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
{
int i;
@@ -187,7 +125,7 @@ int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
/* Check the file descriptors for available data */
do {
errno = 0;
SDLNet_SetLastError(0);
/* Set up the mask of file descriptors */
FD_ZERO(&mask);
@@ -201,7 +139,7 @@ int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
/* Look! */
retval = select(maxfd+1, &mask, NULL, NULL, &tv);
} while ( errno == EINTR );
} while ( SDLNet_GetLastError() == EINTR );
/* Mark all file descriptors ready that have data available */
if ( retval > 0 ) {
@@ -213,8 +151,7 @@ int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
}
return(retval);
}
#endif /* MACOS_OPENTRANSPORT */
/* Free a set of sockets allocated by SDL_NetAllocSocketSet() */
extern void SDLNet_FreeSocketSet(SDLNet_SocketSet set)
{