/ src / utility.cpp
utility.cpp
 1  #include <darlingserver/utility.hpp>
 2  #include <unistd.h>
 3  
 4  DarlingServer::FD::FD():
 5  	_fd(-1)
 6  	{};
 7  
 8  DarlingServer::FD::FD(int fd):
 9  	_fd(fd)
10  	{};
11  
12  DarlingServer::FD::~FD() {
13  	if (_fd != -1) {
14  		close(_fd);
15  	}
16  };
17  
18  DarlingServer::FD::FD(FD&& other):
19  	_fd(other._fd)
20  {
21  	other._fd = -1;
22  };
23  
24  DarlingServer::FD& DarlingServer::FD::operator=(FD&& other) {
25  	if (_fd != -1) {
26  		close(_fd);
27  	}
28  	_fd = other._fd;
29  	other._fd = -1;
30  	return *this;
31  };
32  
33  int DarlingServer::FD::fd() const {
34  	return _fd;
35  };
36  
37  int DarlingServer::FD::extract() {
38  	auto fd = _fd;
39  	_fd = -1;
40  	return fd;
41  };
42  
43  DarlingServer::FD::operator bool() {
44  	return _fd != -1;
45  };