Mir
fd.h
Go to the documentation of this file.
1/*
2 * Copyright © 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
21namespace 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.
28{
30};
31class Fd
32{
33public:
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 /// Prevent accidental calling of ::close()
48 friend auto close(Fd const& fd) -> int = delete;
49private:
50 std::shared_ptr<int> fd;
51};
52} // namespace mir
53
54#endif // MIR_FD_H_
Definition: fd.h:32
friend auto close(Fd const &fd) -> int=delete
Prevent accidental calling of ::close()
operator int() const
Fd(Fd &&)
Fd(Fd const &)=default
Fd(int fd)
Fd(IntOwnedFd)
static int const invalid
Definition: fd.h:38
Fd & operator=(Fd)
Definition: runner.h:27
Definition: fd.h:28
int int_owned_fd
Definition: fd.h:29

Copyright © 2012-2023 Canonical Ltd.
Generated on Tue 2 May 10:01:24 UTC 2023
This documentation is licensed under the GPL version 2 or 3.