From 5f8658582ec1ee084e1f1a9da6c9d0a0f40ac9b5 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Fri, 26 Jul 2002 14:45:50 +0000 Subject: [PATCH] sync with openbsd; API change: timeout_ is now evtimer_ svn:r29 --- event.3 | 49 +++++++++++++++++++++++----------------------- event.c | 2 ++ event.h | 12 +++++++----- kqueue.c | 17 +++++++++++----- sample/time-test.c | 2 +- select.c | 2 ++ 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/event.3 b/event.3 index e063a658..29ab4c99 100644 --- a/event.3 +++ b/event.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: timeout.9,v 1.11 2000/10/12 18:06:03 aaron Exp $ +.\" $OpenBSD: event.3,v 1.4 2002/07/12 18:50:48 provos Exp $ .\" .\" Copyright (c) 2000 Artur Grabowski .\" All rights reserved. @@ -37,19 +37,20 @@ .Nm event_add , .Nm event_del , .Nm event_pending , -.Nm event_initalized , -.Nm timeout_set , -.Nm timeout_add , -.Nm timeout_del -.Nm timeout_pending , -.Nm timeout_initalized , +.Nm event_initialized , +.Nm evtimer_set , +.Nm evtimer_add , +.Nm evtimer_del +.Nm evtimer_pending , +.Nm evtimer_initialized , .Nm signal_set , .Nm signal_add , .Nm signal_del .Nm signal_pending , -.Nm signal_initalized , +.Nm signal_initialized .Nd execute a function when a specific event occurs .Sh SYNOPSIS +.Fd #include .Fd #include .Ft void .Fn "event_init" @@ -68,15 +69,15 @@ .Ft int .Fn "event_initialized" "struct event *ev" .Ft void -.Fn "timeout_set" "struct event *ev" "void (*fn)(int, short, void *)" "void *arg" +.Fn "evtimer_set" "struct event *ev" "void (*fn)(int, short, void *)" "void *arg" .Ft void -.Fn "timeout_add" "struct event *ev" "struct timeval *" +.Fn "evtimer_add" "struct event *ev" "struct timeval *" .Ft void -.Fn "timeout_del" "struct event *ev" +.Fn "evtimer_del" "struct event *ev" .Ft int -.Fn "timeout_pending" "struct event *ev" "struct timeval *tv" +.Fn "evtimer_pending" "struct event *ev" "struct timeval *tv" .Ft int -.Fn "timeout_initialized" "struct event *ev" +.Fn "evtimer_initialized" "struct event *ev" .Ft void .Fn "signal_set" "struct event *ev" "int signal" "void (*fn)(int, short, void *)" "void *arg" .Ft void @@ -99,7 +100,7 @@ on a file descriptor occurs or after at a given time has passed. .Pp The .Nm event -API needs to be initalized with +API needs to be initialized with .Fn event_init before it can be used. .Pp @@ -158,7 +159,7 @@ The event will be prepared to call the function specified by the .Fa fn argument with an .Fa int -argument indicating the file descriptor, with a +argument indicating the file descriptor, a .Fa short argument indicating the type of event, and a .Fa void * @@ -169,8 +170,8 @@ The .Fa fd indicates the file descriptor that should be monitored for events. The events can be either -.Va EV_READ, -.Va EV_WRITE, +.Va EV_READ , +.Va EV_WRITE , or both. Indicating that an application can read or write from the file descriptor respectively without blocking. @@ -198,8 +199,8 @@ structure can be used repeatedly with .Fn event_add and .Fn event_del -and does not need to be reinitialized unless you wish to -change the function called and/or the argument to it. +and does not need to be reinitialized unless the function called and/or +the argument to it are to be changed. .Pp The function .Fn event_add @@ -252,12 +253,12 @@ The macro can be used to check if an event has been initialized. .Pp The functions -.Fn timeout_set , -.Fn timeout_add , -.Fn timeout_del , -.Fn timeout_initialized , +.Fn evtimer_set , +.Fn evtimer_add , +.Fn evtimer_del , +.Fn evtimer_initialized , and -.Fn timeout_pending +.Fn evtimer_pending are abbreviations for common situations where only a timeout is required. The file descriptor passed will be 0, and the event type will be .Va EV_TIMEOUT . diff --git a/event.c b/event.c index 4d5d6af7..8195fffa 100644 --- a/event.c +++ b/event.c @@ -1,3 +1,5 @@ +/* $OpenBSD: event.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ + /* * Copyright 2000-2002 Niels Provos * All rights reserved. diff --git a/event.h b/event.h index a9ad3ec5..e50050e2 100644 --- a/event.h +++ b/event.h @@ -1,3 +1,5 @@ +/* $OpenBSD: event.h,v 1.4 2002/07/12 18:50:48 provos Exp $ */ + /* * Copyright 2000-2002 Niels Provos * All rights reserved. @@ -125,11 +127,11 @@ int timeout_next(struct timeval *); void timeout_correct(struct timeval *); void timeout_process(void); -#define timeout_add(ev, tv) event_add(ev, tv) -#define timeout_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg) -#define timeout_del(ev) event_del(ev) -#define timeout_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv) -#define timeout_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) +#define evtimer_add(ev, tv) event_add(ev, tv) +#define evtimer_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg) +#define evtimer_del(ev) event_del(ev) +#define evtimer_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv) +#define evtimer_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) #define signal_add(ev, tv) event_add(ev, tv) #define signal_set(ev, x, cb, arg) \ diff --git a/kqueue.c b/kqueue.c index c7a9a427..fa106d4d 100644 --- a/kqueue.c +++ b/kqueue.c @@ -1,3 +1,5 @@ +/* $OpenBSD: kqueue.c,v 1.5 2002/07/10 14:41:31 art Exp $ */ + /* * Copyright 2000-2002 Niels Provos * All rights reserved. @@ -36,6 +38,7 @@ #include #include #include +#include #include #include @@ -236,7 +239,7 @@ kq_dispatch(void *arg, struct timeval *tv) for (i = 0; i < res; i++) { /* XXX */ - int ncalls, res; + int ncalls, evres; if (events[i].flags & EV_ERROR || events[i].filter == NULL) continue; @@ -248,13 +251,13 @@ kq_dispatch(void *arg, struct timeval *tv) ncalls = 0; if (ev->ev_flags & EVLIST_ACTIVE) { ncalls = ev->ev_ncalls; - res = ev->ev_res; + evres = ev->ev_res; } ev->ev_flags &= ~EVLIST_X_KQINKERNEL; event_del(ev); if (ncalls) - event_active(ev, res, ncalls); + event_active(ev, evres, ncalls); } return (0); @@ -292,7 +295,9 @@ kq_add(void *arg, struct event *ev) memset(&kev, 0, sizeof(kev)); kev.ident = ev->ev_fd; kev.filter = EVFILT_READ; - kev.flags = EV_ADD | EV_ONESHOT; + kev.flags = EV_ADD; + if (!(ev->ev_events & EV_PERSIST)) + kev.filter |= EV_ONESHOT; kev.udata = ev; if (kq_insert(kqop, &kev) == -1) @@ -305,7 +310,9 @@ kq_add(void *arg, struct event *ev) memset(&kev, 0, sizeof(kev)); kev.ident = ev->ev_fd; kev.filter = EVFILT_WRITE; - kev.flags = EV_ADD | EV_ONESHOT; + kev.flags = EV_ADD; + if (!(ev->ev_events & EV_PERSIST)) + kev.filter |= EV_ONESHOT; kev.udata = ev; if (kq_insert(kqop, &kev) == -1) diff --git a/sample/time-test.c b/sample/time-test.c index 4f42f006..86c14724 100644 --- a/sample/time-test.c +++ b/sample/time-test.c @@ -44,7 +44,7 @@ main (int argc, char **argv) event_init(); /* Initalize one event */ - timeout_set(&timeout, timeout_cb, &timeout); + evtimer_set(&timeout, timeout_cb, &timeout); timerclear(&tv); tv.tv_sec = 2; diff --git a/select.c b/select.c index 4cd77c63..fc5b6da4 100644 --- a/select.c +++ b/select.c @@ -1,3 +1,5 @@ +/* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ + /* * Copyright 2000-2002 Niels Provos * All rights reserved. -- 2.40.0