-
Notifications
You must be signed in to change notification settings - Fork 2
/
file_descriptor.h
50 lines (37 loc) · 1.39 KB
/
file_descriptor.h
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
#ifndef FILE_DESCIPTOR_H
#define FILE_DESCIPTOR_H
#include <assert.h>
#include <unistd.h>
#include <type_traits>
#include <utility>
struct file_descriptor;
struct weak_file_descriptor
{
weak_file_descriptor() noexcept;
explicit weak_file_descriptor(int fd) noexcept;
weak_file_descriptor(file_descriptor const&) noexcept;
weak_file_descriptor(weak_file_descriptor const& other) noexcept;
weak_file_descriptor& operator=(weak_file_descriptor const& other) noexcept;
void close() noexcept;
int getfd() const noexcept;
friend void swap(weak_file_descriptor& a, weak_file_descriptor& b) noexcept;
private:
int fd;
};
struct file_descriptor : weak_file_descriptor
{
typedef weak_file_descriptor weak;
file_descriptor() noexcept;
file_descriptor(int fd) noexcept;
file_descriptor(file_descriptor const& other) = delete;
file_descriptor(file_descriptor&& other) noexcept;
~file_descriptor() noexcept;
file_descriptor& operator=(file_descriptor&& rhs) noexcept;
weak release() noexcept;
void reset(int new_fd) noexcept;
friend void swap(file_descriptor& a, file_descriptor& b) noexcept;
};
size_t read_some(weak_file_descriptor fd, void* data, size_t size);
size_t write_some(weak_file_descriptor fd, void const* data, std::size_t size);
void write(weak_file_descriptor fdc, const void *data, std::size_t size);
#endif // FILE_DESCIPTOR_H