Mercurial > code
changeset 472:f8594d3394ab
Socket: don't set macros if already defined at command line
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 05 Nov 2015 16:42:23 +0100 |
parents | 35729a52fda5 |
children | 5a9671dabb15 |
files | C++/modules/Socket/Sockets.h |
diffstat | 1 files changed, 62 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/modules/Socket/Sockets.h Thu Nov 05 14:54:08 2015 +0100 +++ b/C++/modules/Socket/Sockets.h Thu Nov 05 16:42:23 2015 +0100 @@ -23,11 +23,15 @@ * @file Sockets.h * @brief Portable socket abstraction * + * # Introduction + * * This file is a portable networking library. * - * ### User definable options + * ## Options * - * User may set the following variables before compiling these files: + * The user may set the following variables before compiling these files: + * + * ### General options * * - **SOCKET_NO_AUTO_INIT**: (bool) Set to 0 if you don't want Socket class to * automatically calls net::init function and net::finish functions. @@ -37,35 +41,17 @@ * * ### Options for Listener class * - * Feature detection, multiple implementations may be avaible, for example, - * Linux has poll, select and epoll. + * Feature detection, multiple implementations may be avaible, for example, Linux has poll, select and epoll. * - * We assume that select(2) is always available. + * We assume that `select(2)` is always available. * - * Of course, you can set the variables yourself if you test it with your - * build system. + * Of course, you can set the variables yourself if you test it with your build system. * * - **SOCKET_HAVE_POLL**: Defined on all BSD, Linux. Also defined on Windows - * if _WIN32_WINNT is set to 0x0600 or greater. + * if _WIN32_WINNT is set to 0x0600 or greater. * - **SOCKET_HAVE_KQUEUE**: Defined on all BSD and Apple. * - **SOCKET_HAVE_EPOLL**: Defined on Linux only. - */ - -#if defined(_WIN32) -# if _WIN32_WINNT >= 0x0600 -# define SOCKET_HAVE_POLL -# endif -#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) -# define SOCKET_HAVE_KQUEUE -# define SOCKET_HAVE_POLL -#elif defined(__linux__) -# define SOCKET_HAVE_EPOLL -# define SOCKET_HAVE_POLL -#endif - -/** - * This sets the default backend to use depending on the system. The following - * table summaries. + * - **SOCKET_DEFAULT_BACKEND**: Which backend to use (e.g. `Select`). * * The preference priority is ordered from left to right. * @@ -78,29 +64,66 @@ */ #if defined(_WIN32) -# if defined(SOCKET_HAVE_POLL) -# define SOCKET_DEFAULT_BACKEND Poll +# if _WIN32_WINNT >= 0x0600 && !defined(SOCKET_HAVE_POLL) +# define SOCKET_HAVE_POLL +# endif +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) +# if !defined(SOCKET_HAVE_KQUEUE) +# define SOCKET_HAVE_KQUEUE +# endif +# if !defined(SOCKET_HAVE_POLL) +# define SOCKET_HAVE_POLL +# endif +#elif defined(__linux__) +# if !defined(SOCKET_HAVE_EPOLL) +# define SOCKET_HAVE_EPOLL +# endif +# if !defined(SOCKET_HAVE_POLL) +# define SOCKET_HAVE_POLL +# endif +#endif + +/* + * Define SOCKET_DEFAULT_BACKEND + * ------------------------------------------------------------------ + */ + +/** + * Defines the default Listener backend to use. + * + * @note Do not rely on the value shown in doxygen. + */ +#if !defined(SOCKET_DEFAULT_BACKEND) +# if defined(_WIN32) +# if defined(SOCKET_HAVE_POLL) +# define SOCKET_DEFAULT_BACKEND Poll +# else +# define SOCKET_DEFAULT_BACKEND Select +# endif +# elif defined(__linux__) +# include <sys/epoll.h> + +# define SOCKET_DEFAULT_BACKEND Epoll +# elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) +# include <sys/types.h> +# include <sys/event.h> +# include <sys/time.h> + +# define SOCKET_DEFAULT_BACKEND Kqueue # else # define SOCKET_DEFAULT_BACKEND Select # endif -#elif defined(__linux__) -# include <sys/epoll.h> - -# define SOCKET_DEFAULT_BACKEND Epoll -#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) -# include <sys/types.h> -# include <sys/event.h> -# include <sys/time.h> - -# define SOCKET_DEFAULT_BACKEND Kqueue -#else -# define SOCKET_DEFAULT_BACKEND Select #endif #if defined(SOCKET_HAVE_POLL) && !defined(_WIN32) # include <poll.h> #endif +/* + * Headers to include + * ------------------------------------------------------------------ + */ + #if defined(_WIN32) # include <cstdlib>