LCOV - code coverage report
Current view: top level - common - socket_utils.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 1 1 100.0 %
Date: 2019-05-16 09:13:18 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       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
       6                 :            :  *
       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.
      11                 :            :  *
      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.
      16                 :            :  *
      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
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_SOCKET_UTILS_H
      23                 :            : #define XAPIAN_INCLUDED_SOCKET_UTILS_H
      24                 :            : 
      25                 :            : #include "safenetdb.h"
      26                 :            : #include "safeunistd.h"
      27                 :            : 
      28                 :            : #ifdef __WIN32__
      29                 :            : 
      30                 :            : #include "safewinsock2.h"
      31                 :            : 
      32                 :            : /// Convert an fd (which might be a socket) to a WIN32 HANDLE.
      33                 :            : extern HANDLE fd_to_handle(int fd);
      34                 :            : 
      35                 :            : /// Close an fd, which might be a socket.
      36                 :            : extern void close_fd_or_socket(int fd);
      37                 :            : #else
      38                 :            : // There's no distinction between sockets and other fds on UNIX.
      39                 :       1436 : inline void close_fd_or_socket(int fd) { close(fd); }
      40                 :            : #endif
      41                 :            : 
      42                 :            : /** Attempt to set socket-level timeouts.
      43                 :            :  *
      44                 :            :  *  These aren't supported by all platforms, and some platforms allow them to
      45                 :            :  *  set but ignore them, so we can't easily report failure.
      46                 :            :  *
      47                 :            :  *  Also sets SO_KEEPALIVE (if supported), which should ensure a stuck
      48                 :            :  *  connection will eventually time out, though it may take up to ~2 hours.
      49                 :            :  */
      50                 :            : void set_socket_timeouts(int fd, double timeout);
      51                 :            : 
      52                 :            : constexpr size_t PRETTY_IP6_LEN =
      53                 :            :     (INET6_ADDRSTRLEN > INET_ADDRSTRLEN ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN);
      54                 :            : 
      55                 :            : int pretty_ip6(const void* p, char* buf);
      56                 :            : 
      57                 :            : #endif // XAPIAN_INCLUDED_SOCKET_UTILS_H

Generated by: LCOV version 1.11