[ci] Enable IRC notifications from travis
[xapian.git] / xapian-core / common / socket_utils.h
blob1f0137e2897ddaed878f3a30051a5bce75934760
1 /** @file socket_utils.h
2 * @brief Socket handling utilities.
3 */
4 /* Copyright (C) 2006,2007,2008,2015 Olly Betts
5 * Copyright (C) 2008 Lemur Consulting Ltd
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef XAPIAN_INCLUDED_SOCKET_UTILS_H
23 #define XAPIAN_INCLUDED_SOCKET_UTILS_H
25 #include "safeunistd.h"
27 #ifdef __WIN32__
29 #include "safewinsock2.h"
31 /// Convert an fd (which might be a socket) to a WIN32 HANDLE.
32 extern HANDLE fd_to_handle(int fd);
34 /// Close an fd, which might be a socket.
35 extern void close_fd_or_socket(int fd);
36 #else
37 // There's no distinction between sockets and other fds on UNIX.
38 inline void close_fd_or_socket(int fd) { close(fd); }
39 #endif
41 /** Attempt to set socket-level timeouts.
43 * These aren't supported by all platforms, and some platforms allow them to
44 * set but ignore them, so we can't easily report failure.
46 * Also sets SO_KEEPALIVE (if supported), which should ensure a stuck
47 * connection will eventually time out, though it may take up to ~2 hours.
49 void set_socket_timeouts(int fd, double timeout);
51 #endif // XAPIAN_INCLUDED_SOCKET_UTILS_H