blob: a545a800c217078d0b29a18e86ff50fcf3b109d7 [file] [log] [blame]
Austin Schuh6c590f82019-09-11 19:23:12 -07001#ifndef AOS_IPC_LIB_SIGNALFD_H_
2#define AOS_IPC_LIB_SIGNALFD_H_
3
4#include <sys/signalfd.h>
5#include <sys/types.h>
6#include <initializer_list>
7
8namespace aos {
9namespace ipc_lib {
10
11// Class to manage a signalfd.
12class SignalFd {
13 public:
14 // Constructs a SignalFd for the provided list of signals.
15 // Blocks the signals at the same time in this thread.
16 SignalFd(::std::initializer_list<int> signals);
17
18 SignalFd(const SignalFd &) = delete;
19 SignalFd &operator=(const SignalFd &) = delete;
20 ~SignalFd();
21
22 // Returns the file descriptor for the signalfd.
23 int fd() { return fd_; }
24
25 // Reads a signalfd_siginfo. If there was an error, the resulting ssi_signo
26 // will be 0.
27 signalfd_siginfo Read();
28
29 private:
30 int fd_ = -1;
31
32 sigset_t mask_;
33};
34
35} // namespace ipc_lib
36} // namespace aos
37
38#endif // AOS_IPC_LIB_SIGNALFD_H_