00001 /* safesysselect.h: #include <sys/select.h> with portability workarounds. 00002 * 00003 * Copyright (C) 2007,2011 Olly Betts 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License as 00007 * published by the Free Software Foundation; either version 2 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #ifndef XAPIAN_INCLUDED_SAFESYSSELECT_H 00021 #define XAPIAN_INCLUDED_SAFESYSSELECT_H 00022 00023 #ifndef PACKAGE 00024 # error You must #include <config.h> before #include "safesysselect.h" 00025 #endif 00026 00027 #ifndef __WIN32__ 00028 # ifdef HAVE_SYS_SELECT_H 00029 // According to POSIX 1003.1-2001. 00030 # include <sys/select.h> 00031 # else 00032 // According to earlier standards. 00033 # include <sys/time.h> 00034 # include <sys/types.h> 00035 # include <unistd.h> 00036 # endif 00037 00038 // On Solaris FDSET uses memset but fails to prototype it. 00039 # include <cstring> 00040 00041 #else 00042 // Under __WIN32__, socket() returns the unsigned type SOCKET. We can safely 00043 // assign that to an int (it'll be a non-negative fd or INVALID_SOCKET, which 00044 // will cast to -1 as an int), but when we use int in FD_SET, we get a warning 00045 // about comparing signed and unsigned, so we add a wrapper to cast the fd 00046 // argument of FD_SET to unsigned. 00047 00048 // select() and FD_SET() are defined in <winsock2.h>: 00049 # include "safewinsock2.h" 00050 inline void xapian_FD_SET_(int fd, fd_set *set) { 00051 FD_SET((unsigned)fd, set); 00052 } 00053 # ifdef FD_SET 00054 # undef FD_SET 00055 # endif 00056 # define FD_SET(FD,SET) xapian_FD_SET_(FD,SET) 00057 #endif 00058 00059 #endif // XAPIAN_INCLUDED_SAFESYSSELECT_H