diff options
author | rubidium <rubidium@openttd.org> | 2007-01-02 19:19:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-01-02 19:19:48 +0000 |
commit | 66bbf336c6af7353ef0aeed58002c46543b30635 (patch) | |
tree | ad4a63860df2626b22f77e7dac712e958bea54cb /src/network/core/os_abstraction.h | |
parent | ccc0a3f4dbf58c005b22341ac8874252924690cd (diff) | |
download | openttd-66bbf336c6af7353ef0aeed58002c46543b30635.tar.xz |
(svn r7759) -Merge: makefile rewrite. This merge features:
- A proper ./configure, so everything needs to be configured only once, not for every make.
- Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies.
- A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC.
- Proper support for OSX universal binaries.
- Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files.
- Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files.
Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy.
Diffstat (limited to 'src/network/core/os_abstraction.h')
-rw-r--r-- | src/network/core/os_abstraction.h | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h new file mode 100644 index 000000000..c7df16a93 --- /dev/null +++ b/src/network/core/os_abstraction.h @@ -0,0 +1,181 @@ +/* $Id$ */ + +#ifndef NETWORK_CORE_OS_ABSTRACTION_H +#define NETWORK_CORE_OS_ABSTRACTION_H + +/** + * @file os_abstraction.h Network stuff has many things that needs to be + * included and/or implemented by default. + * All those things are in this file. + */ + +/* Include standard stuff per OS */ + +#ifdef ENABLE_NETWORK + +/* Windows stuff */ +#if defined(WIN32) || defined(WIN64) +#include <winsock2.h> +#include <ws2tcpip.h> +#include <windows.h> + +#if !(defined(__MINGW32__) || defined(__CYGWIN__)) + /* Windows has some different names for some types */ + typedef SSIZE_T ssize_t; + typedef int socklen_t; +#endif + +#define GET_LAST_ERROR() WSAGetLastError() +#define EWOULDBLOCK WSAEWOULDBLOCK +/* Windows has some different names for some types */ +typedef unsigned long in_addr_t; +#endif /* WIN32 */ + +/* UNIX stuff */ +#if defined(UNIX) +# define SOCKET int +# define INVALID_SOCKET -1 +# if !defined(__MORPHOS__) && !defined(__AMIGA__) +# define ioctlsocket ioctl +# if !defined(BEOS_NET_SERVER) +# define closesocket close +# endif +# define GET_LAST_ERROR() (errno) +# endif +/* Need this for FIONREAD on solaris */ +# define BSD_COMP + +/* Includes needed for UNIX-like systems */ +# include <unistd.h> +# include <sys/ioctl.h> +# if defined(__BEOS__) && defined(BEOS_NET_SERVER) +# include <be/net/socket.h> +# include <be/kernel/OS.h> // snooze() +# include <be/net/netdb.h> + typedef unsigned long in_addr_t; +# define INADDR_NONE INADDR_BROADCAST +# else +# include <sys/socket.h> +# include <netinet/in.h> +# include <netinet/tcp.h> +# include <arpa/inet.h> +# include <net/if.h> +/* According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3. */ +# if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__INNOTEK_LIBC__) \ + && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) +/* If for any reason ifaddrs.h does not exist on your system, comment out + * the following two lines and an alternative way will be used to fetch + * the list of IPs from the system. */ +# include <ifaddrs.h> +# define HAVE_GETIFADDRS +# endif +# if defined(SUNOS) || defined(__MORPHOS__) || defined(__BEOS__) +# define INADDR_NONE 0xffffffff +# endif +# if defined(__BEOS__) && !defined(BEOS_NET_SERVER) + /* needed on Zeta */ +# include <sys/sockio.h> +# endif +# endif /* BEOS_NET_SERVER */ + +# if !defined(__BEOS__) && defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1) + typedef uint32_t in_addr_t; +# endif + +# include <errno.h> +# include <sys/time.h> +# include <netdb.h> +#endif // UNIX + +#ifdef __BEOS__ + typedef int socklen_t; +#endif + +/* OS/2 stuff */ +#if defined(__OS2__) +# define SOCKET int +# define INVALID_SOCKET -1 +# define ioctlsocket ioctl +# define closesocket close +# define GET_LAST_ERROR() (sock_errno()) + +/* Includes needed for OS/2 systems */ +# include <types.h> +# include <unistd.h> +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <netinet/in.h> +# include <netinet/tcp.h> +# include <arpa/inet.h> +# include <net/if.h> +# include <errno.h> +# include <sys/time.h> +# include <netdb.h> +# include <nerrno.h> +# define INADDR_NONE 0xffffffff + +typedef int socklen_t; +#if !defined(__INNOTEK_LIBC__) +typedef unsigned long in_addr_t; +#endif /* __INNOTEK_LIBC__ */ +#endif /* OS/2 */ + +/* MorphOS and Amiga stuff */ +#if defined(__MORPHOS__) || defined(__AMIGA__) +# include <exec/types.h> +# include <proto/exec.h> // required for Open/CloseLibrary() +# if defined(__MORPHOS__) +# include <sys/filio.h> // FIO* defines +# include <sys/sockio.h> // SIO* defines +# include <netinet/in.h> +# else /* __AMIGA__ */ +# include <proto/socket.h> +# endif + +/* Make the names compatible */ +# define closesocket(s) CloseSocket(s) +# define GET_LAST_ERROR() Errno() +# define ioctlsocket(s,request,status) IoctlSocket((LONG)s,(ULONG)request,(char*)status) +# define ioctl ioctlsocket + + typedef unsigned int in_addr_t; + typedef long socklen_t; + extern struct Library *SocketBase; + +# ifdef __AMIGA__ + /* for usleep() implementation */ + extern struct Device *TimerBase; + extern struct MsgPort *TimerPort; + extern struct timerequest *TimerRequest; +# endif +#endif // __MORPHOS__ || __AMIGA__ + +static inline bool SetNonBlocking(int d) +{ +#ifdef WIN32 + u_long nonblocking = 1; +#else + int nonblocking = 1; +#endif +#if defined(__BEOS__) && defined(BEOS_NET_SERVER) + return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0; +#else + return ioctlsocket(d, FIONBIO, &nonblocking) == 0; +#endif +} + +static inline bool SetNoDelay(int d) +{ + /* XXX should this be done at all? */ +#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server + int b = 1; + /* The (const char*) cast is needed for windows */ + return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b)) == 0; +#else + return true; +#endif +} + +#endif /* ENABLE_NETWORK */ + +#endif /* NETWORK_CORE_OS_ABSTRACTION_H */ |