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> |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame^] | 6 | |
Austin Schuh | 6c590f8 | 2019-09-11 19:23:12 -0700 | [diff] [blame] | 7 | #include <initializer_list> |
| 8 | |
| 9 | namespace aos { |
| 10 | namespace ipc_lib { |
| 11 | |
| 12 | // Class to manage a signalfd. |
| 13 | class SignalFd { |
| 14 | public: |
| 15 | // Constructs a SignalFd for the provided list of signals. |
| 16 | // Blocks the signals at the same time in this thread. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 17 | SignalFd(::std::initializer_list<unsigned int> signals); |
Austin Schuh | 6c590f8 | 2019-09-11 19:23:12 -0700 | [diff] [blame] | 18 | |
| 19 | SignalFd(const SignalFd &) = delete; |
| 20 | SignalFd &operator=(const SignalFd &) = delete; |
| 21 | ~SignalFd(); |
| 22 | |
| 23 | // Returns the file descriptor for the signalfd. |
| 24 | int fd() { return fd_; } |
| 25 | |
| 26 | // Reads a signalfd_siginfo. If there was an error, the resulting ssi_signo |
| 27 | // will be 0. |
| 28 | signalfd_siginfo Read(); |
| 29 | |
| 30 | private: |
| 31 | int fd_ = -1; |
| 32 | |
Brian Silverman | 407cc53 | 2019-11-03 11:40:56 -0800 | [diff] [blame] | 33 | // The signals we blocked in the constructor. |
| 34 | sigset_t blocked_mask_; |
Austin Schuh | 6c590f8 | 2019-09-11 19:23:12 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | } // namespace ipc_lib |
| 38 | } // namespace aos |
| 39 | |
| 40 | #endif // AOS_IPC_LIB_SIGNALFD_H_ |