Belle II Software  release-05-01-25
Fifo.cc
1 #include "daq/slc/system/Fifo.h"
2 
3 #include <daq/slc/base/IOException.h>
4 
5 #include <unistd.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 
9 #include <cstdio>
10 
11 using namespace Belle2;
12 
13 Fifo Fifo::mkfifo(const std::string& path)
14 {
15  ::mkfifo(path.c_str(), 0666);
16  Fifo fifo;
17  fifo.open(path.c_str());
18  return fifo;
19 }
20 
21 void Fifo::open(const std::string& path, const std::string& mode_s)
22 {
23  int mode = O_RDONLY;
24  if (mode_s.find("w") != std::string::npos) {
25  mode = O_WRONLY;
26  if (mode_s.find("r") != std::string::npos) {
27  mode = O_RDWR;
28  }
29  }
30  if ((m_fd = ::open(path.c_str(), mode)) < 0) {
31  perror("open");
32  throw (IOException("Failed to open fifo."));
33  }
34 }
35 
36 void Fifo::unlink(const std::string& path)
37 {
38  if ((::unlink(path.c_str())) < 0) {
39  perror("unlink");
40  }
41  close();
42 }
43 
44 size_t Fifo::write(const void* buf, size_t count)
45 {
46  return ::write(m_fd, buf, count);
47 }
48 
49 size_t Fifo::read(void* buf, size_t count)
50 {
51  return ::read(m_fd, buf, count);
52 }
Belle2::Fifo
Definition: Fifo.h:15
Belle2::IOException
Definition: IOException.h:12
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19