blob: b3a906352292362d7e322f1caf3bf33f0878e790 [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
Brian Silverman407cc532019-11-03 11:40:56 -080032 // The signals we blocked in the constructor.
33 sigset_t blocked_mask_;
Austin Schuh6c590f82019-09-11 19:23:12 -070034};
35
36} // namespace ipc_lib
37} // namespace aos
38
39#endif // AOS_IPC_LIB_SIGNALFD_H_