Belle II Software development
FileDescriptor Class Reference
Inheritance diagram for FileDescriptor:
Fifo File Inotify TCPServerSocket TCPSocket UDPSocket

Public Member Functions

 FileDescriptor (int fd)
 
int get_fd () const
 
bool select (int sec=-1, int usec=-1)
 
bool select2 (int sec=-1, int usec=-1)
 
bool close ()
 

Protected Attributes

int m_fd
 

Detailed Description

Definition at line 17 of file FileDescriptor.h.

Constructor & Destructor Documentation

◆ FileDescriptor() [1/2]

Definition at line 18 of file FileDescriptor.cc.

19{
20 m_fd = -1;
21}

◆ FileDescriptor() [2/2]

FileDescriptor ( int  fd)

Definition at line 23 of file FileDescriptor.cc.

24{
25 m_fd = fd;
26}

◆ ~FileDescriptor()

~FileDescriptor ( )
virtual

Definition at line 28 of file FileDescriptor.cc.

29{
30
31}

Member Function Documentation

◆ close()

bool close ( )

Definition at line 90 of file FileDescriptor.cc.

91{
92 if (m_fd > 0) {
93 if (::close(m_fd) != 0) {
94 return false;
95 }
96 }
97 m_fd = -1;
98 return true;
99}

◆ get_fd()

int get_fd ( ) const

Definition at line 33 of file FileDescriptor.cc.

34{
35 return m_fd;
36}

◆ select()

bool select ( int  sec = -1,
int  usec = -1 
)

Definition at line 38 of file FileDescriptor.cc.

39{
40 if (m_fd <= 0) {
41 return false;
42 }
43 fd_set fds;
44 FD_ZERO(&fds);
45 FD_SET(m_fd, &fds);
46 int ret;
47 if (sec >= 0 && usec >= 0) {
48 timeval t = {sec, usec};
49 ret = ::select(FD_SETSIZE, &fds, NULL, NULL, &t);
50 } else {
51 ret = ::select(FD_SETSIZE, &fds, NULL, NULL, NULL);
52 }
53 if (ret < 0) {
54 perror("select");
55 throw (IOException("Failed to select"));
56 }
57 if (FD_ISSET(m_fd, &fds)) {
58 return true;
59 } else {
60 return false;
61 }
62}

◆ select2()

bool select2 ( int  sec = -1,
int  usec = -1 
)

Definition at line 64 of file FileDescriptor.cc.

65{
66 if (m_fd <= 0) {
67 return false;
68 }
69 fd_set fds;
70 FD_ZERO(&fds);
71 FD_SET(m_fd, &fds);
72 int ret;
73 if (sec >= 0 && usec >= 0) {
74 timeval t = {sec, usec};
75 ret = ::select(FD_SETSIZE, NULL, &fds, NULL, &t);
76 } else {
77 ret = ::select(FD_SETSIZE, NULL, &fds, NULL, NULL);
78 }
79 if (ret < 0) {
80 perror("select");
81 throw (IOException("Failed to select"));
82 }
83 if (FD_ISSET(m_fd, &fds)) {
84 return true;
85 } else {
86 return false;
87 }
88}

Member Data Documentation

◆ m_fd

int m_fd
protected

Definition at line 31 of file FileDescriptor.h.


The documentation for this class was generated from the following files: