LCOV - code coverage report
Current view: top level - net - remotetcpclient.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 2 2 100.0 %
Date: 2019-02-17 14:59:59 Functions: 1 1 100.0 %
Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file remotetcpclient.h
       2                 :            :  *  @brief TCP/IP socket based RemoteDatabase implementation
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2010,2011,2014 Olly Betts
       5                 :            :  *
       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.
      10                 :            :  *
      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.
      15                 :            :  *
      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
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_REMOTETCPCLIENT_H
      22                 :            : #define XAPIAN_INCLUDED_REMOTETCPCLIENT_H
      23                 :            : 
      24                 :            : #include "backends/remote/remote-database.h"
      25                 :            : 
      26                 :            : #ifdef __WIN32__
      27                 :            : # define SOCKET_INITIALIZER_MIXIN private WinsockInitializer,
      28                 :            : #else
      29                 :            : # define SOCKET_INITIALIZER_MIXIN
      30                 :            : #endif
      31                 :            : 
      32                 :            : /** TCP/IP socket based RemoteDatabase implementation.
      33                 :            :  *
      34                 :            :  *  Connects via TCP/IP to an instance of xapian-tcpsrv.
      35                 :            :  */
      36                 :            : class RemoteTcpClient : SOCKET_INITIALIZER_MIXIN public RemoteDatabase {
      37                 :            :     /// Don't allow assignment.
      38                 :            :     void operator=(const RemoteTcpClient &);
      39                 :            : 
      40                 :            :     /// Don't allow copying.
      41                 :            :     RemoteTcpClient(const RemoteTcpClient &);
      42                 :            : 
      43                 :            :     /** Attempt to open a TCP/IP socket connection to xapian-tcpsrv.
      44                 :            :      *
      45                 :            :      *  Connect to xapian-tcpsrv running on port @a port of host @a hostname.
      46                 :            :      *  Give up trying to connect after @a timeout_connect seconds.
      47                 :            :      *
      48                 :            :      *  Note: this method is called early on during class construction before
      49                 :            :      *  any member variables or even the base class have been initialised.
      50                 :            :      *  To help avoid accidentally trying to use member variables or call other
      51                 :            :      *  methods which do, this method has been deliberately made "static".
      52                 :            :      */
      53                 :            :     static int open_socket(const std::string & hostname, int port,
      54                 :            :                            double timeout_connect);
      55                 :            : 
      56                 :            :     /** Get a context string for use when constructing Xapian::NetworkError.
      57                 :            :      *
      58                 :            :      *  Note: this method is used from constructors so has been made static to
      59                 :            :      *  avoid problems with trying to use uninitialised member variables.  In
      60                 :            :      *  particular, it can't be made a virtual method of the base class.
      61                 :            :      */
      62                 :            :     static std::string get_tcpcontext(const std::string & hostname, int port);
      63                 :            : 
      64                 :            :   public:
      65                 :            :     /** Constructor.
      66                 :            :      *
      67                 :            :      *  Attempts to open a TCP/IP connection to xapian-tcpsrv running on port
      68                 :            :      *  @a port of host @a hostname.
      69                 :            :      *
      70                 :            :      *  @param timeout_connect  Timeout for trying to connect (in seconds).
      71                 :            :      *  @param timeout          Timeout during communication after successfully
      72                 :            :      *                          connecting (in seconds).
      73                 :            :      *  @param writable         Is this a WritableDatabase?
      74                 :            :      *  @param flags            Xapian::DB_RETRY_LOCK or 0.
      75                 :            :      */
      76                 :        358 :     RemoteTcpClient(const std::string & hostname, int port,
      77                 :            :                     double timeout_, double timeout_connect, bool writable,
      78                 :            :                     int flags)
      79                 :            :         : RemoteDatabase(open_socket(hostname, port, timeout_connect),
      80                 :            :                          timeout_, get_tcpcontext(hostname, port),
      81 [ +  + ][ +  - ]:        358 :                          writable, flags) { }
      82                 :            : 
      83                 :            :     /** Destructor. */
      84                 :            :     ~RemoteTcpClient();
      85                 :            : };
      86                 :            : 
      87                 :            : #endif  // XAPIAN_INCLUDED_REMOTETCPCLIENT_H

Generated by: LCOV version 1.11