Austin Schuh | 6c590f8 | 2019-09-11 19:23:12 -0700 | [diff] [blame] | 1 | #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 | |
| 8 | namespace aos { |
| 9 | namespace ipc_lib { |
| 10 | |
| 11 | // Class to manage a signalfd. |
| 12 | class 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 Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 16 | SignalFd(::std::initializer_list<unsigned int> signals); |
Austin Schuh | 6c590f8 | 2019-09-11 19:23:12 -0700 | [diff] [blame] | 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 | |
Brian Silverman | 407cc53 | 2019-11-03 11:40:56 -0800 | [diff] [blame] | 32 | // The signals we blocked in the constructor. |
| 33 | sigset_t blocked_mask_; |
Austin Schuh | 6c590f8 | 2019-09-11 19:23:12 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | } // namespace ipc_lib |
| 37 | } // namespace aos |
| 38 | |
| 39 | #endif // AOS_IPC_LIB_SIGNALFD_H_ |