Mir
fd.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2 or 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef MIR_FD_H_
17 #define MIR_FD_H_
18 
19 #include <memory>
20 
21 namespace mir
22 {
23 //TODO: remove once mir::Fd is used more pervasively.
24 // some existing code does not really allow us to transfer or share the ownership
25 // of the fd. Constructing using mir::Fd(IntOwnedFd(int)) will help transition the existing
26 // code to using the mir::Fd type properly.
27 struct IntOwnedFd
28 {
30 };
31 class Fd
32 {
33 public:
34  //transfer ownership of the POD-int to the object. The int no longer needs close()ing,
35  //and has the lifetime of the Fd object.
36  explicit Fd(int fd);
37  explicit Fd(IntOwnedFd);
38  static int const invalid{-1};
39  Fd(); //Initializes fd to the mir::Fd::invalid;
40  Fd(Fd&&);
41  Fd(Fd const&) = default;
43 
44  //bit of a convenient kludge. take care not to close or otherwise destroy the FD.
45  operator int() const;
46 
47 private:
48  std::shared_ptr<int> fd;
49 };
50 } // namespace mir
51 
52 #endif // MIR_FD_H_

Copyright © 2012-2022 Canonical Ltd.
Generated on Thu Sep 8 12:37:23 UTC 2022
This documentation is licensed under the GPL version 2 or 3.