From: root Date: Thu, 29 Nov 2007 12:21:05 +0000 (+0000) Subject: many fixes to event emulation X-Git-Tag: rel-1_6~14 X-Git-Url: https://git.llucax.com/software/libev.git/commitdiff_plain/8d0f4d263d9a5601bb7d419e7db00970e288cb7e many fixes to event emulation --- diff --git a/ev.3 b/ev.3 index 9e1c613..d7652a3 100644 --- a/ev.3 +++ b/ev.3 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title """ 1" -.TH "" 1 "2007-11-28" "perl v5.8.8" "User Contributed Perl Documentation" +.TH "" 1 "2007-11-29" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" libev \- a high performance full\-featured event loop written in C .SH "SYNOPSIS" @@ -1073,23 +1073,25 @@ timer will not fire more than once per event loop iteration. This will act as if the timer timed out and restart it again if it is repeating. The exact semantics are: .Sp -If the timer is started but nonrepeating, stop it. +If the timer is pending, its pending status is cleared. .Sp -If the timer is repeating, either start it if necessary (with the repeat -value), or reset the running timer to the repeat value. +If the timer is started but nonrepeating, stop it (as if it timed out). +.Sp +If the timer is repeating, either start it if necessary (with the +\&\f(CW\*(C`repeat\*(C'\fR value), or reset the running timer to the \f(CW\*(C`repeat\*(C'\fR value. .Sp This sounds a bit complicated, but here is a useful and typical -example: Imagine you have a tcp connection and you want a so-called -idle timeout, that is, you want to be called when there have been, -say, 60 seconds of inactivity on the socket. The easiest way to do -this is to configure an \f(CW\*(C`ev_timer\*(C'\fR with \f(CW\*(C`after\*(C'\fR=\f(CW\*(C`repeat\*(C'\fR=\f(CW60\fR and calling +example: Imagine you have a tcp connection and you want a so-called idle +timeout, that is, you want to be called when there have been, say, 60 +seconds of inactivity on the socket. The easiest way to do this is to +configure an \f(CW\*(C`ev_timer\*(C'\fR with a \f(CW\*(C`repeat\*(C'\fR value of \f(CW60\fR and then call \&\f(CW\*(C`ev_timer_again\*(C'\fR each time you successfully read or write some data. If you go into an idle state where you do not expect data to travel on the -socket, you can stop the timer, and again will automatically restart it if -need be. +socket, you can \f(CW\*(C`ev_timer_stop\*(C'\fR the timer, and \f(CW\*(C`ev_timer_again\*(C'\fR will +automatically restart it if need be. .Sp -You can also ignore the \f(CW\*(C`after\*(C'\fR value and \f(CW\*(C`ev_timer_start\*(C'\fR altogether -and only ever use the \f(CW\*(C`repeat\*(C'\fR value: +That means you can ignore the \f(CW\*(C`after\*(C'\fR value and \f(CW\*(C`ev_timer_start\*(C'\fR +altogether and only ever use the \f(CW\*(C`repeat\*(C'\fR value and \f(CW\*(C`ev_timer_again\*(C'\fR: .Sp .Vb 8 \& ev_timer_init (timer, callback, 0., 5.); @@ -1102,8 +1104,8 @@ and only ever use the \f(CW\*(C`repeat\*(C'\fR value: \& ev_timer_again (loop, timer); .Ve .Sp -This is more efficient then stopping/starting the timer eahc time you want -to modify its timeout value. +This is more slightly efficient then stopping/starting the timer each time +you want to modify its timeout value. .IP "ev_tstamp repeat [read\-write]" 4 .IX Item "ev_tstamp repeat [read-write]" The current \f(CW\*(C`repeat\*(C'\fR value. Will be used each time the watcher times out diff --git a/ev.html b/ev.html index 6c59bec..08d84d5 100644 --- a/ev.html +++ b/ev.html @@ -6,7 +6,7 @@ - + @@ -954,20 +954,21 @@ timer will not fire more than once per event loop iteration.

This will act as if the timer timed out and restart it again if it is repeating. The exact semantics are:

-

If the timer is started but nonrepeating, stop it.

-

If the timer is repeating, either start it if necessary (with the repeat -value), or reset the running timer to the repeat value.

+

If the timer is pending, its pending status is cleared.

+

If the timer is started but nonrepeating, stop it (as if it timed out).

+

If the timer is repeating, either start it if necessary (with the +repeat value), or reset the running timer to the repeat value.

This sounds a bit complicated, but here is a useful and typical -example: Imagine you have a tcp connection and you want a so-called -idle timeout, that is, you want to be called when there have been, -say, 60 seconds of inactivity on the socket. The easiest way to do -this is to configure an ev_timer with after=repeat=60 and calling +example: Imagine you have a tcp connection and you want a so-called idle +timeout, that is, you want to be called when there have been, say, 60 +seconds of inactivity on the socket. The easiest way to do this is to +configure an ev_timer with a repeat value of 60 and then call ev_timer_again each time you successfully read or write some data. If you go into an idle state where you do not expect data to travel on the -socket, you can stop the timer, and again will automatically restart it if -need be.

-

You can also ignore the after value and ev_timer_start altogether -and only ever use the repeat value:

+socket, you can ev_timer_stop the timer, and ev_timer_again will +automatically restart it if need be.

+

That means you can ignore the after value and ev_timer_start +altogether and only ever use the repeat value and ev_timer_again:

   ev_timer_init (timer, callback, 0., 5.);
    ev_timer_again (loop, timer);
    ...
@@ -978,8 +979,8 @@ and only ever use the repeat value:

ev_timer_again (loop, timer);
-

This is more efficient then stopping/starting the timer eahc time you want -to modify its timeout value.

+

This is more slightly efficient then stopping/starting the timer each time +you want to modify its timeout value.

ev_tstamp repeat [read-write]
diff --git a/ev.pod b/ev.pod index aaf225d..1e0234c 100644 --- a/ev.pod +++ b/ev.pod @@ -918,23 +918,25 @@ timer will not fire more than once per event loop iteration. This will act as if the timer timed out and restart it again if it is repeating. The exact semantics are: -If the timer is started but nonrepeating, stop it. +If the timer is pending, its pending status is cleared. -If the timer is repeating, either start it if necessary (with the repeat -value), or reset the running timer to the repeat value. +If the timer is started but nonrepeating, stop it (as if it timed out). + +If the timer is repeating, either start it if necessary (with the +C value), or reset the running timer to the C value. This sounds a bit complicated, but here is a useful and typical -example: Imagine you have a tcp connection and you want a so-called -idle timeout, that is, you want to be called when there have been, -say, 60 seconds of inactivity on the socket. The easiest way to do -this is to configure an C with C=C=C<60> and calling +example: Imagine you have a tcp connection and you want a so-called idle +timeout, that is, you want to be called when there have been, say, 60 +seconds of inactivity on the socket. The easiest way to do this is to +configure an C with a C value of C<60> and then call C each time you successfully read or write some data. If you go into an idle state where you do not expect data to travel on the -socket, you can stop the timer, and again will automatically restart it if -need be. +socket, you can C the timer, and C will +automatically restart it if need be. -You can also ignore the C value and C altogether -and only ever use the C value: +That means you can ignore the C value and C +altogether and only ever use the C value and C: ev_timer_init (timer, callback, 0., 5.); ev_timer_again (loop, timer); @@ -945,8 +947,8 @@ and only ever use the C value: timer->again = 10.; ev_timer_again (loop, timer); -This is more efficient then stopping/starting the timer eahc time you want -to modify its timeout value. +This is more slightly efficient then stopping/starting the timer each time +you want to modify its timeout value. =item ev_tstamp repeat [read-write] diff --git a/event.c b/event.c index 1666f62..1d30ce5 100644 --- a/event.c +++ b/event.c @@ -160,13 +160,8 @@ x_cb_io (EV_P_ struct ev_io *w, int revents) { struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io)); - if (revents & EV_ERROR) + if ((revents & EV_ERROR) || !(ev->ev_events & EV_PERSIST)) event_del (ev); - else if (!(ev->ev_events & EV_PERSIST) && ev_is_active (w)) - { - ev_io_stop (EV_A_ w); - ev->ev_flags &= ~EVLIST_INSERTED; - } x_cb (ev, revents); } @@ -237,8 +232,10 @@ int event_add (struct event *ev, struct timeval *tv) ev->ev_flags |= EVLIST_TIMEOUT; } else - if (ev_is_active (&ev->to)) + { ev_timer_stop (EV_A_ &ev->to); + ev->ev_flags &= ~EVLIST_TIMEOUT; + } ev->ev_flags |= EVLIST_ACTIVE; @@ -250,17 +247,9 @@ int event_del (struct event *ev) dLOOPev; if (ev->ev_events & EV_SIGNAL) - { - /* sig */ - if (ev_is_active (&ev->iosig.sig)) - ev_signal_stop (EV_A_ &ev->iosig.sig); - } + ev_signal_stop (EV_A_ &ev->iosig.sig); else if (ev->ev_events & (EV_READ | EV_WRITE)) - { - /* io */ - if (ev_is_active (&ev->iosig.io)) - ev_io_stop (EV_A_ &ev->iosig.io); - } + ev_io_stop (EV_A_ &ev->iosig.io); if (ev_is_active (&ev->to)) ev_timer_stop (EV_A_ &ev->to);