Belle II Software development
Fifo Class Reference
Inheritance diagram for Fifo:
FileDescriptor

Public Member Functions

void open (const std::string &path, const std::string &mode="r")
 
void unlink (const std::string &path)
 
virtual size_t write (const void *v, size_t count)
 
virtual size_t read (void *v, size_t count)
 
int get_fd () const
 
bool select (int sec=-1, int usec=-1)
 
bool select2 (int sec=-1, int usec=-1)
 
bool close ()
 

Static Public Member Functions

static Fifo mkfifo (const std::string &path)
 

Protected Attributes

int m_fd
 

Detailed Description

Definition at line 22 of file Fifo.h.

Constructor & Destructor Documentation

◆ Fifo()

Fifo ( )
inline

Definition at line 28 of file Fifo.h.

28{}

◆ ~Fifo()

virtual ~Fifo ( )
inlinevirtual

Definition at line 29 of file Fifo.h.

29{}

Member Function Documentation

◆ close()

bool close ( )
inherited

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
inherited

Definition at line 33 of file FileDescriptor.cc.

34{
35 return m_fd;
36}

◆ mkfifo()

Fifo mkfifo ( const std::string &  path)
static

Definition at line 20 of file Fifo.cc.

21{
22 ::mkfifo(path.c_str(), 0666);
23 Fifo fifo;
24 fifo.open(path.c_str());
25 return fifo;
26}

◆ open()

void open ( const std::string &  path,
const std::string &  mode = "r" 
)

Definition at line 28 of file Fifo.cc.

29{
30 int mode = O_RDONLY;
31 if (mode_s.find("w") != std::string::npos) {
32 mode = O_WRONLY;
33 if (mode_s.find("r") != std::string::npos) {
34 mode = O_RDWR;
35 }
36 }
37 if ((m_fd = ::open(path.c_str(), mode)) < 0) {
38 perror("open");
39 throw (IOException("Failed to open fifo."));
40 }
41}

◆ read()

size_t read ( void *  v,
size_t  count 
)
virtual

Definition at line 56 of file Fifo.cc.

57{
58 return ::read(m_fd, buf, count);
59}

◆ select()

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

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 
)
inherited

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}

◆ unlink()

void unlink ( const std::string &  path)

Definition at line 43 of file Fifo.cc.

44{
45 if ((::unlink(path.c_str())) < 0) {
46 perror("unlink");
47 }
48 close();
49}

◆ write()

size_t write ( const void *  v,
size_t  count 
)
virtual

Definition at line 51 of file Fifo.cc.

52{
53 return ::write(m_fd, buf, count);
54}

Member Data Documentation

◆ m_fd

int m_fd
protectedinherited

Definition at line 31 of file FileDescriptor.h.


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