MythTV  master
mythbaseutil.h
Go to the documentation of this file.
1 #ifndef MYTH_BASE_UTIL_H
2 #define MYTH_BASE_UTIL_H
3 
4 // POSIX
5 #include <array>
6 #include <cerrno> // for checking errno
7 #include <fcntl.h> // for fnctl
8 #include <sys/types.h> // for fnctl
9 
10 // Qt
11 #include <QString>
12 
13 // MythTV
14 #include "mythlogging.h"
15 
16 using pipe_fd_array = std::array<int,2>;
17 using pipe_flag_array = std::array<long,2>;
18 
19 #ifdef _WIN32
20 static inline void setup_pipe(pipe_fd_array&, pipe_flag_array&) {}
21 #else
22 static inline void setup_pipe(pipe_fd_array& mypipe, pipe_flag_array& myflags)
23 {
24  int pipe_ret = pipe(mypipe.data());
25  if (pipe_ret < 0)
26  {
27  LOG(VB_GENERAL, LOG_ERR, "Failed to open pipes" + ENO);
28  mypipe.fill(-1);
29  }
30  else
31  {
32  errno = 0;
33  long flags = fcntl(mypipe[0], F_GETFL);
34  if (0 == errno)
35  {
36  int ret = fcntl(mypipe[0], F_SETFL, flags|O_NONBLOCK);
37  if (ret < 0)
38  LOG(VB_GENERAL, LOG_ERR,
39  QString("Set pipe flags error") + ENO);
40  }
41  else
42  {
43  LOG(VB_GENERAL, LOG_ERR, QString("Get pipe flags error") + ENO);
44  }
45 
46  for (uint i = 0; i < 2; i++)
47  {
48  errno = 0;
49  flags = fcntl(mypipe[i], F_GETFL);
50  if (0 == errno)
51  myflags[i] = flags;
52  }
53  }
54 }
55 #endif
56 
57 #endif // MYTH_BASE_UTIL_H
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:72
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythlogging.h
setup_pipe
static void setup_pipe(pipe_fd_array &, pipe_flag_array &)
Definition: mythbaseutil.h:20
O_NONBLOCK
#define O_NONBLOCK
Definition: mythmedia.cpp:25
pipe_flag_array
std::array< long, 2 > pipe_flag_array
Definition: mythbaseutil.h:17
uint
unsigned int uint
Definition: compat.h:140
pipe_fd_array
std::array< int, 2 > pipe_fd_array
Definition: mythbaseutil.h:16