Mir
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
include
common
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 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
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17
*/
18
#ifndef MIR_FD_H_
19
#define MIR_FD_H_
20
21
#include <memory>
22
23
namespace
mir
24
{
25
//TODO: remove once mir::Fd is used more pervasively.
26
// some existing code does not really allow us to transfer or share the ownership
27
// of the fd. Constructing using mir::Fd(IntOwnedFd(int)) will help transition the existing
28
// code to using the mir::Fd type properly.
29
struct
IntOwnedFd
30
{
31
int
int_owned_fd
;
32
};
33
class
Fd
34
{
35
public
:
36
//transfer ownership of the POD-int to the object. The int no longer needs close()ing,
37
//and has the lifetime of the Fd object.
38
explicit
Fd
(
int
fd);
39
explicit
Fd
(
IntOwnedFd
);
40
static
int
const
invalid
{-1};
41
Fd
();
//Initializes fd to the mir::Fd::invalid;
42
Fd
(
Fd
&&);
43
Fd
(
Fd
const
&) =
default
;
44
Fd
&
operator=
(
Fd
);
45
46
//bit of a convenient kludge. take care not to close or otherwise destroy the FD.
47
operator
int()
const
;
48
49
private
:
50
std::shared_ptr<int> fd;
51
};
52
}
// namespace mir
53
54
#endif // MIR_FD_H_
mir
All things Mir.
Definition:
aging_buffer.h:24
mir::Fd
Definition:
fd.h:33
mir::IntOwnedFd
Definition:
fd.h:29
mir::Fd::Fd
Fd()
Definition:
fd.cpp:22
mir::Fd::invalid
static int const invalid
Definition:
fd.h:40
mir::IntOwnedFd::int_owned_fd
int int_owned_fd
Definition:
fd.h:31
mir::Fd::operator=
Fd & operator=(Fd)
Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014