Fix comment typo
[xapian.git] / xapian-core / common / safesysselect.h
blob476a8a2feeeda41d30d40475ab366fb2c6254283
1 /** @file safesysselect.h
2 * @brief #include <sys/select.h> with portability workarounds.
3 */
4 /* Copyright (C) 2007,2011 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef XAPIAN_INCLUDED_SAFESYSSELECT_H
22 #define XAPIAN_INCLUDED_SAFESYSSELECT_H
24 #ifndef PACKAGE
25 # error You must #include <config.h> before #include "safesysselect.h"
26 #endif
28 #ifndef __WIN32__
29 # ifdef HAVE_SYS_SELECT_H
30 // According to POSIX 1003.1-2001.
31 # include <sys/select.h>
32 # else
33 // According to earlier standards.
34 # include <sys/time.h>
35 # include <sys/types.h>
36 # include <unistd.h>
37 # endif
39 // On Solaris FD_SET uses memset but fails to prototype it.
40 # include <cstring>
42 #else
43 // Under __WIN32__, socket() returns the unsigned type SOCKET. We can safely
44 // assign that to an int (it'll be a non-negative fd or INVALID_SOCKET, which
45 // will cast to -1 as an int), but when we use int in FD_SET, we get a warning
46 // about comparing signed and unsigned, so we add a wrapper to cast the fd
47 // argument of FD_SET to unsigned.
49 // select() and FD_SET() are defined in <winsock2.h>:
50 # include "safewinsock2.h"
51 inline void xapian_FD_SET_(int fd, fd_set *set) {
52 FD_SET(unsigned(fd), set);
54 # ifdef FD_SET
55 # undef FD_SET
56 # endif
57 # define FD_SET(FD,SET) xapian_FD_SET_(FD,SET)
58 #endif
60 #endif // XAPIAN_INCLUDED_SAFESYSSELECT_H