Add unix signal integration with the iomux

This commit is contained in:
Nils O. Selåsdal
2015-11-28 15:38:21 +01:00
parent 9bb7cc335a
commit a8dffbc71e
2 changed files with 327 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#ifndef UC_IOMUX_SIGNAL_H_
#define UC_IOMUX_SIGNAL_H_
#include "ucore/iomux.h"
/** Callback signature for handling unix signals.
* @param mux associated mux
* @param signo unix signal number
* @param cookie value passed to iomux_register_unixsignal
*/
typedef void (*IOMuxSignalHandler)(struct IOMux *mux, int signo, void *cookie);
/** Register a handler for a unix signal.
* The handler is invoked as normally within the iomux loop.
* Note, only one handler per signal can be used.
*
* The current implementation has the limitation that only
* one IOMux can globally be registered to handle signals.
* All signals must be unregistered prior to deleting the
* IOMux that is set up to handle signals.
*
* @param mux associated IOMux
* @param signo the signal (see man signal) to handle
* @param handler callback that will be called whrn the signal is caught
* @param cookie value passed back to the handler
*
* @return 0 on success, errno if registring the signal failed.
* (EINVAL if another mux is registered for signals,
* EEXISTS if a signal handler is already registered for the signo
* ENOMEM if memory allocation failed
* other errno values from syscalls)
*
*/
int iomux_register_unixsignal(struct IOMux *mux,
int signo,
IOMuxSignalHandler handler,
void *cookie);
/** Unregister the current handler for a signal.
*
* @param mux associated mux
* @param signo signal number handler to unregister
* @return 0 on success, errno value on failure (ENOENT if
* no signal handler was registered for signo)
*/
int iomux_unregister_unixsignal(struct IOMux *mux, int signo);
#endif