-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_descriptor.h
48 lines (37 loc) · 884 Bytes
/
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
//
// Created by jackson on 29.04.16.
//
#ifndef KIMBERLY_FILE_DESCRIPTOR_H
#define KIMBERLY_FILE_DESCRIPTOR_H
#include <unistd.h>
class file_descriptor {
public:
static int const INVALID_FD = -1;
file_descriptor(const file_descriptor&) = delete;
file_descriptor(file_descriptor&& other)
: fd(other.fd)
{
other.fd = INVALID_FD;
}
file_descriptor(int fd) : fd(fd) { }
file_descriptor() : fd(INVALID_FD) { }
/*file_descriptor(file_descriptor &&rhs) {
fd = rhs.fd;
rhs.fd = 0;
}*/
~file_descriptor() {
Log::d("Closing fd(" + inttostr(fd) + ")");
if (fd != INVALID_FD)
close(fd);
Log::d("closed");
}
int get_fd() const {
return fd;
}
void set_fd(int fd) {
this->fd = fd;
}
private:
int fd;
};
#endif //KIMBERLY_FILE_DESCRIPTOR_H