-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathlinux.hpp
More file actions
104 lines (81 loc) · 1.87 KB
/
linux.hpp
File metadata and controls
104 lines (81 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_DETAIL_LINUX_HPP_INCLUDED
#define CPPCORO_DETAIL_LINUX_HPP_INCLUDED
#include <cppcoro/config.hpp>
#if !CPPCORO_OS_LINUX
# error <cppcoro/detail/linux.hpp> is only supported on the Linux platform.
#endif
#include <utility>
#include <cstdint>
namespace cppcoro
{
namespace detail
{
namespace linux
{
struct io_state
{
using callback_type = void(
io_state* state,
std::int32_t res);
io_state(callback_type* callback = nullptr) noexcept
: m_callback(callback)
{}
callback_type* m_callback;
};
class safe_file_descriptor
{
public:
safe_file_descriptor()
: m_fd(-1)
{}
explicit safe_file_descriptor(int fd)
: m_fd(fd)
{}
safe_file_descriptor(const safe_file_descriptor& other) = delete;
safe_file_descriptor(safe_file_descriptor&& other) noexcept
: m_fd(other.m_fd)
{
other.m_fd = -1;
}
~safe_file_descriptor()
{
close();
}
safe_file_descriptor& operator=(safe_file_descriptor fd) noexcept
{
swap(fd);
return *this;
}
constexpr int get() const { return m_fd; }
void close() noexcept;
void swap(safe_file_descriptor& other) noexcept
{
std::swap(m_fd, other.m_fd);
}
bool operator==(const safe_file_descriptor& other) const
{
return m_fd == other.m_fd;
}
bool operator!=(const safe_file_descriptor& other) const
{
return m_fd != other.m_fd;
}
bool operator==(int fd) const
{
return m_fd == fd;
}
bool operator!=(int fd) const
{
return m_fd != fd;
}
private:
int m_fd;
};
}
}
}
#endif