blob: 7d2021ab25ac640981e3bab64111731150013c1b [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.
Alex Perrycb7da4b2019-08-28 19:35:56 -070016 SignalFd(::std::initializer_list<unsigned int> signals);
Austin Schuh6c590f82019-09-11 19:23:12 -070017
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_