xapian-core  1.4.25
fdtracker.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2010,2018 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_FDTRACKER_H
22 #define XAPIAN_INCLUDED_FDTRACKER_H
23 
24 #include <string>
25 #include <vector>
26 
27 // Disable fd tracking where it can't possibly work.
28 #ifndef __WIN32__
29 # define XAPIAN_TESTSUITE_TRACK_FDS
30 #endif
31 
32 class FDTracker {
33 #ifdef XAPIAN_TESTSUITE_TRACK_FDS
34 
40  std::vector<bool> fds;
41 
47  void * dir_void;
48 
49  std::string message;
50 
51  void mark_fd(int fd);
52 
53  bool check_fd(int fd) const;
54 
55  public:
56  FDTracker() : dir_void(NULL) { }
57 
58  ~FDTracker();
59 
60  void init();
61 
62  bool check();
63 
64  const std::string & get_message() const { return message; }
65 #else
66  public:
67  FDTracker() { }
68 
69  void init() { }
70 
71  bool check() { return true; }
72 
73  std::string get_message() const { return std::string(); }
74 #endif
75 
76  FDTracker(const FDTracker&) = delete;
77 
78  FDTracker& operator=(const FDTracker&) = delete;
79 };
80 
81 #endif // XAPIAN_INCLUDED_FDTRACKER_H
void * dir_void
The DIR* from opendir("/proc/self/fd") (or equivalent) cast to void*.
Definition: fdtracker.h:47
FDTracker()
Definition: fdtracker.h:56
~FDTracker()
Definition: fdtracker.cc:68
FDTracker & operator=(const FDTracker &)=delete
std::string message
Definition: fdtracker.h:49
const std::string & get_message() const
Definition: fdtracker.h:64
void init()
Definition: fdtracker.cc:77
bool check()
Definition: fdtracker.cc:108
bool check_fd(int fd) const
Definition: fdtracker.cc:63
void mark_fd(int fd)
Definition: fdtracker.cc:53
std::vector< bool > fds
Which fds are open.
Definition: fdtracker.h:40