tron@2186: /* $Id$ */ tron@2186: rubidium@5720: /** rubidium@5720: * @file os_abstraction.h Network stuff has many things that needs to be rubidium@5720: * included and/or implemented by default. rubidium@5720: * All those things are in this file. rubidium@5720: */ truelight@543: celestar@6447: #ifndef NETWORK_CORE_OS_ABSTRACTION_H celestar@6447: #define NETWORK_CORE_OS_ABSTRACTION_H celestar@6447: rubidium@5720: /* Include standard stuff per OS */ truelight@543: Darkvater@1812: #ifdef ENABLE_NETWORK Darkvater@1812: rubidium@5720: /* Windows stuff */ Darkvater@2482: #if defined(WIN32) || defined(WIN64) darkvater@796: #include darkvater@796: #include Darkvater@2482: #include darkvater@792: darkvater@1505: #if !(defined(__MINGW32__) || defined(__CYGWIN__)) rubidium@5720: /* Windows has some different names for some types */ darkvater@796: typedef SSIZE_T ssize_t; darkvater@1342: typedef int socklen_t; darkvater@796: #endif darkvater@796: darkvater@796: #define GET_LAST_ERROR() WSAGetLastError() darkvater@796: #define EWOULDBLOCK WSAEWOULDBLOCK rubidium@5720: /* Windows has some different names for some types */ truelight@543: typedef unsigned long in_addr_t; rubidium@5720: #endif /* WIN32 */ truelight@543: rubidium@5720: /* UNIX stuff */ truelight@5791: #if defined(UNIX) && !defined(__OS2__) truelight@543: # define SOCKET int truelight@543: # define INVALID_SOCKET -1 truelight@543: # if !defined(__MORPHOS__) && !defined(__AMIGA__) truelight@543: # define ioctlsocket ioctl truelight@543: # if !defined(BEOS_NET_SERVER) truelight@543: # define closesocket close truelight@543: # endif truelight@543: # define GET_LAST_ERROR() (errno) truelight@543: # endif rubidium@5720: /* Need this for FIONREAD on solaris */ truelight@543: # define BSD_COMP truelight@543: rubidium@5720: /* Includes needed for UNIX-like systems */ truelight@543: # include truelight@543: # include truelight@543: # if defined(__BEOS__) && defined(BEOS_NET_SERVER) truelight@543: # include truelight@543: # include // snooze() truelight@543: # include truelight@543: typedef unsigned long in_addr_t; truelight@543: # define INADDR_NONE INADDR_BROADCAST truelight@543: # else truelight@543: # include truelight@543: # include truelight@543: # include truelight@543: # include truelight@543: # include rubidium@5720: /* According to glibc/NEWS, appeared in glibc-2.3. */ Darkvater@5305: # if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__INNOTEK_LIBC__) \ truelight@1687: && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) rubidium@5720: /* If for any reason ifaddrs.h does not exist on your system, comment out rubidium@5720: * the following two lines and an alternative way will be used to fetch rubidium@5720: * the list of IPs from the system. */ tron@706: # include tron@706: # define HAVE_GETIFADDRS pasky@1412: # endif pasky@1412: # if defined(SUNOS) || defined(__MORPHOS__) || defined(__BEOS__) tron@706: # define INADDR_NONE 0xffffffff pasky@1412: # endif tron@1051: # if defined(__BEOS__) && !defined(BEOS_NET_SERVER) rubidium@5720: /* needed on Zeta */ tron@1051: # include tron@1051: # endif rubidium@5720: # endif /* BEOS_NET_SERVER */ truelight@789: Darkvater@1812: # if !defined(__BEOS__) && defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1) truelight@789: typedef uint32_t in_addr_t; pasky@1412: # endif truelight@789: truelight@543: # include truelight@543: # include truelight@543: # include truelight@543: #endif // UNIX truelight@543: tron@1429: #ifdef __BEOS__ darkvater@1441: typedef int socklen_t; tron@1429: #endif tron@1429: truelight@6227: #if defined(PSP) truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: # include truelight@6227: truelight@6227: # define TCP_NODELAY 1 truelight@6227: # define SO_NONBLOCK 0x1009 truelight@6227: # define SOCKET int truelight@6227: # define INVALID_SOCKET -1 truelight@6227: # define INADDR_NONE 0xffffffff truelight@6227: # define closesocket close truelight@6227: # define GET_LAST_ERROR() sceNetInetGetErrno() truelight@6227: #endif /* PSP */ truelight@6227: rubidium@5720: /* OS/2 stuff */ truelight@781: #if defined(__OS2__) truelight@781: # define SOCKET int truelight@781: # define INVALID_SOCKET -1 truelight@781: # define ioctlsocket ioctl truelight@781: # define closesocket close truelight@810: # define GET_LAST_ERROR() (sock_errno()) truelight@781: rubidium@5720: /* Includes needed for OS/2 systems */ truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@810: # define INADDR_NONE 0xffffffff truelight@781: darkvater@1507: typedef int socklen_t; Darkvater@5305: #if !defined(__INNOTEK_LIBC__) truelight@781: typedef unsigned long in_addr_t; Darkvater@5305: #endif /* __INNOTEK_LIBC__ */ rubidium@5720: #endif /* OS/2 */ truelight@781: rubidium@5720: /* MorphOS and Amiga stuff */ truelight@543: #if defined(__MORPHOS__) || defined(__AMIGA__) truelight@543: # include rubidium@5720: # include // required for Open/CloseLibrary() truelight@6092: /* MorphOS defines his network functions with UBYTE arrays while we truelight@6092: * use char arrays. This gives tons of unneeded warnings */ truelight@6092: # define UBYTE char truelight@543: # if defined(__MORPHOS__) rubidium@5720: # include // FIO* defines rubidium@5720: # include // SIO* defines tron@1343: # include rubidium@5720: # else /* __AMIGA__ */ truelight@543: # include truelight@543: # endif truelight@543: rubidium@5720: /* Make the names compatible */ truelight@543: # define closesocket(s) CloseSocket(s) truelight@543: # define GET_LAST_ERROR() Errno() celestar@9910: # define ioctlsocket(s, request, status) IoctlSocket((LONG)s, (ULONG)request, (char*)status) bjarni@770: # define ioctl ioctlsocket truelight@543: bjarni@770: typedef unsigned int in_addr_t; tron@1343: typedef long socklen_t; bjarni@770: extern struct Library *SocketBase; bjarni@770: bjarni@770: # ifdef __AMIGA__ rubidium@5720: /* for usleep() implementation */ bjarni@770: extern struct Device *TimerBase; bjarni@770: extern struct MsgPort *TimerPort; bjarni@770: extern struct timerequest *TimerRequest; bjarni@770: # endif truelight@543: #endif // __MORPHOS__ || __AMIGA__ truelight@543: rubidium@6226: static inline bool SetNonBlocking(SOCKET d) tron@1332: { rubidium@5720: #ifdef WIN32 tron@1466: u_long nonblocking = 1; rubidium@5720: #else tron@1332: int nonblocking = 1; rubidium@5720: #endif truelight@6227: #if (defined(__BEOS__) && defined(BEOS_NET_SERVER)) || defined(PSP) tron@1332: return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0; rubidium@5720: #else tron@1332: return ioctlsocket(d, FIONBIO, &nonblocking) == 0; rubidium@5720: #endif tron@1332: } tron@1332: rubidium@6226: static inline bool SetNoDelay(SOCKET d) tron@1332: { rubidium@5720: /* XXX should this be done at all? */ rubidium@5720: #if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server tron@1332: int b = 1; rubidium@5720: /* The (const char*) cast is needed for windows */ tron@1332: return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b)) == 0; rubidium@5720: #else tron@1332: return true; rubidium@5720: #endif tron@1332: } tron@1332: bjarni@5734: #ifdef __APPLE__ bjarni@5734: /* Looks like sys/socket.h uses a name we got in macros.h */ bjarni@5734: #undef ALIGN bjarni@5734: #endif bjarni@5734: Darkvater@1812: #endif /* ENABLE_NETWORK */ Darkvater@1812: rubidium@5720: #endif /* NETWORK_CORE_OS_ABSTRACTION_H */