[quake3] Mergine unix_net.c and win_net.c questions
Ryan C. Gordon
icculus at icculus.org
Wed Aug 15 16:25:24 EDT 2007
> I thought about #defining SOCKET_ERROR -1 and stuff like that, but I
> wasn't sure if that would be acceptable. Is it?
Most games I've worked on end up #define'ing and typedef'ing a handful
of things at the start to unify WinSock and BSD differences, and then
use mostly the same code after that:
typedef int SOCKET;
typedef struct hostent HOSTENT;
typedef in_addr IN_ADDR;
typedef struct sockaddr SOCKADDR;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct linger LINGER;
typedef struct timeval TIMEVAL;
typedef TCHAR* LPSTR;
typedef socklen_t SOCKLEN;
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define WSAEWOULDBLOCK EAGAIN
#define WSAEINPROGRESS EINPROGRESS
#define WSAENOTSOCK ENOTSOCK
#define WSATRY_AGAIN TRY_AGAIN
#define WSAHOST_NOT_FOUND HOST_NOT_FOUND
#define WSANO_DATA NO_ADDRESS
#define LPSOCKADDR sockaddr*
#define WSAECONNRESET ECONNRESET
#define closesocket close
#define ioctlsocket ioctl
#define WSAGetLastError() errno
(etc)
...these can map from BSD sockets to WinSock too, of course, but I
usually end up moving WinSock code to Unix and not the other way around.
The number of #ifdef's past that block tends to be extremely minimal.
--ryan.
More information about the quake3
mailing list