[ci] Fix clang-santisers job for GHA change
[xapian.git] / xapian-core / net / progclient.h
blob1f939c6202bb5febc05d1c5a0a405ad1860a68d5
1 /** @file
2 * @brief Implementation of RemoteDatabase using a spawned server.
3 */
4 /* Copyright (C) 2007,2010,2011,2014,2019,2023,2024 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_PROGCLIENT_H
22 #define XAPIAN_INCLUDED_PROGCLIENT_H
24 #include <string>
25 #include <string_view>
27 #include <sys/types.h>
29 #include "backends/remote/remote-database.h"
31 /** Implementation of RemoteDatabase using a spawned server.
33 * ProgClient spawns a child process to connect to the server - for example,
34 * an ssh command to run the server on a remote host. Communication with the
35 * child process is via a pipe.
37 class ProgClient : public RemoteDatabase {
38 /// Don't allow assignment.
39 ProgClient& operator=(const ProgClient&) = delete;
41 /// Don't allow copying.
42 ProgClient(const ProgClient&) = delete;
44 #ifndef __WIN32__
45 /// Process id of the child process.
46 pid_t child;
47 #else
48 /// HANDLE of the child process.
49 HANDLE child;
50 #endif
52 /** Start the child process.
54 * @param progname The program used to create the connection.
55 * @param args Any arguments to the program.
56 * @param child Reference to store the child process pid/HANDLE in.
58 * @return A std::pair containing the file descriptor for the connection
59 * to the child process and a context string to return with any
60 * error messages.
62 * Note: this method is called early on during class construction before
63 * any member variables or even the base class have been initialised.
64 * To help avoid accidentally trying to use member variables, this method
65 * has been deliberately made "static".
67 static std::pair<int, std::string> run_program(std::string_view progname,
68 std::string_view args,
69 #ifndef __WIN32__
70 pid_t& child
71 #else
72 HANDLE& child
73 #endif
76 public:
77 /** Constructor.
79 * @param progname The program used to create the connection.
80 * @param args Any arguments to the program.
81 * @param timeout_ Timeout for communication (in seconds).
82 * @param writable Is this a WritableDatabase?
83 * @param flags Xapian::DB_RETRY_LOCK or 0.
85 ProgClient(std::string_view progname,
86 std::string_view args,
87 double timeout_,
88 bool writable,
89 int flags)
90 : RemoteDatabase(run_program(progname, args, child),
91 timeout_,
92 writable,
93 flags)
96 /** Destructor. */
97 ~ProgClient();
100 #endif // XAPIAN_INCLUDED_PROGCLIENT_H