mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-11 16:52:26 +07:00
Fix TODO: Add uev_*_start() functions.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
LibuEv TODO
|
||||
===========
|
||||
|
||||
* Add uev_*_start(), at least for I/O, needed by finit
|
||||
* Make port to *BSD kqueue API, http://en.wikipedia.org/wiki/Kqueue
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "uev.h"
|
||||
|
||||
|
||||
@@ -39,12 +41,14 @@
|
||||
*/
|
||||
int uev_io_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int events)
|
||||
{
|
||||
if (fd < 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uev_watcher_init(ctx, w, UEV_IO_TYPE, cb, arg, fd, events))
|
||||
return -1;
|
||||
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
return uev_watcher_start(w);
|
||||
}
|
||||
|
||||
@@ -67,15 +71,28 @@ int uev_io_set(uev_t *w, int fd, int events)
|
||||
return uev_io_init(w->ctx, w, (uev_cb_t *)w->cb, w->arg, fd, events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an I/O watcher
|
||||
* @param w Watcher to start (again)
|
||||
*
|
||||
* @return POSIX OK(0) or non-zero with @param errno set on error.
|
||||
*/
|
||||
int uev_io_start(uev_t *w)
|
||||
{
|
||||
return uev_io_set(w, w->fd, w->events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop an I/O watcher
|
||||
* @param w Pointer to an uev_t watcher
|
||||
* @param w Watcher to stop
|
||||
*
|
||||
* @return POSIX OK(0) or non-zero with @param errno set on error.
|
||||
*/
|
||||
int uev_io_stop(uev_t *w)
|
||||
{
|
||||
return uev_watcher_stop(w);
|
||||
int status = uev_watcher_stop(w);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,12 @@ int uev_signal_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo
|
||||
int fd;
|
||||
sigset_t mask;
|
||||
|
||||
if (!w || !ctx) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
w->fd = -1;
|
||||
|
||||
sigemptyset(&mask);
|
||||
fd = signalfd(-1, &mask, SFD_NONBLOCK);
|
||||
if (fd < 0)
|
||||
@@ -81,6 +87,9 @@ int uev_signal_set(uev_t *w, int signo)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Remember for callbacks and start/stop */
|
||||
w->signo = signo;
|
||||
|
||||
/* Handle stopped signal watchers */
|
||||
if (w->fd < 0) {
|
||||
/* Remove from internal list */
|
||||
@@ -104,6 +113,26 @@ int uev_signal_set(uev_t *w, int signo)
|
||||
return uev_watcher_start(w);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start a stopped signal watcher
|
||||
* @param w Watcher to start (again)
|
||||
*
|
||||
* @return POSIX OK(0) or non-zero with @param errno set on error.
|
||||
*/
|
||||
int uev_signal_start(uev_t *w)
|
||||
{
|
||||
if (!w) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (-1 != w->fd)
|
||||
uev_signal_stop(w);
|
||||
|
||||
return uev_signal_set(w, w->signo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a signal watcher
|
||||
* @param w Watcher to stop
|
||||
|
||||
@@ -130,6 +130,25 @@ int uev_timer_set(uev_t *w, int timeout, int period)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a stopped timer watcher
|
||||
* @param w Watcher to start (again)
|
||||
*
|
||||
* @return POSIX OK(0) or non-zero with @param errno set on error.
|
||||
*/
|
||||
int uev_timer_start(uev_t *w)
|
||||
{
|
||||
if (!w) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (-1 != w->fd)
|
||||
uev_watcher_stop(w);
|
||||
|
||||
return uev_timer_set(w, w->timeout, w->period);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop and unregister a timer watcher
|
||||
* @param w Watcher to stop
|
||||
|
||||
@@ -231,8 +231,6 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
|
||||
if (read(w->fd, &fdsi, sz) != sz)
|
||||
goto exit;
|
||||
|
||||
w->signo = fdsi.ssi_signo;
|
||||
}
|
||||
|
||||
if (w->cb)
|
||||
|
||||
@@ -98,14 +98,17 @@ int uev_run (uev_ctx_t *ctx, int flags);
|
||||
|
||||
int uev_io_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int events);
|
||||
int uev_io_set (uev_t *w, int fd, int events);
|
||||
int uev_io_start (uev_t *w);
|
||||
int uev_io_stop (uev_t *w);
|
||||
|
||||
int uev_timer_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeout, int period);
|
||||
int uev_timer_set (uev_t *w, int timeout, int period);
|
||||
int uev_timer_start (uev_t *w);
|
||||
int uev_timer_stop (uev_t *w);
|
||||
|
||||
int uev_signal_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo);
|
||||
int uev_signal_set (uev_t *w, int signo);
|
||||
int uev_signal_start (uev_t *w);
|
||||
int uev_signal_stop (uev_t *w);
|
||||
|
||||
#endif /* LIBUEV_UEV_H_ */
|
||||
|
||||
Reference in New Issue
Block a user