… | |
… | |
916 | =item ev_timer_again (loop) |
916 | =item ev_timer_again (loop) |
917 | |
917 | |
918 | This will act as if the timer timed out and restart it again if it is |
918 | This will act as if the timer timed out and restart it again if it is |
919 | repeating. The exact semantics are: |
919 | repeating. The exact semantics are: |
920 | |
920 | |
|
|
921 | If the timer is pending, its pending status is cleared. |
|
|
922 | |
921 | If the timer is started but nonrepeating, stop it. |
923 | If the timer is started but nonrepeating, stop it (as if it timed out). |
922 | |
924 | |
923 | If the timer is repeating, either start it if necessary (with the repeat |
925 | If the timer is repeating, either start it if necessary (with the |
924 | value), or reset the running timer to the repeat value. |
926 | C<repeat> value), or reset the running timer to the C<repeat> value. |
925 | |
927 | |
926 | This sounds a bit complicated, but here is a useful and typical |
928 | This sounds a bit complicated, but here is a useful and typical |
927 | example: Imagine you have a tcp connection and you want a so-called |
929 | example: Imagine you have a tcp connection and you want a so-called idle |
928 | idle timeout, that is, you want to be called when there have been, |
930 | timeout, that is, you want to be called when there have been, say, 60 |
929 | say, 60 seconds of inactivity on the socket. The easiest way to do |
931 | seconds of inactivity on the socket. The easiest way to do this is to |
930 | this is to configure an C<ev_timer> with C<after>=C<repeat>=C<60> and calling |
932 | configure an C<ev_timer> with a C<repeat> value of C<60> and then call |
931 | C<ev_timer_again> each time you successfully read or write some data. If |
933 | C<ev_timer_again> each time you successfully read or write some data. If |
932 | you go into an idle state where you do not expect data to travel on the |
934 | you go into an idle state where you do not expect data to travel on the |
933 | socket, you can stop the timer, and again will automatically restart it if |
935 | socket, you can C<ev_timer_stop> the timer, and C<ev_timer_again> will |
934 | need be. |
936 | automatically restart it if need be. |
935 | |
937 | |
936 | You can also ignore the C<after> value and C<ev_timer_start> altogether |
938 | That means you can ignore the C<after> value and C<ev_timer_start> |
937 | and only ever use the C<repeat> value: |
939 | altogether and only ever use the C<repeat> value and C<ev_timer_again>: |
938 | |
940 | |
939 | ev_timer_init (timer, callback, 0., 5.); |
941 | ev_timer_init (timer, callback, 0., 5.); |
940 | ev_timer_again (loop, timer); |
942 | ev_timer_again (loop, timer); |
941 | ... |
943 | ... |
942 | timer->again = 17.; |
944 | timer->again = 17.; |
943 | ev_timer_again (loop, timer); |
945 | ev_timer_again (loop, timer); |
944 | ... |
946 | ... |
945 | timer->again = 10.; |
947 | timer->again = 10.; |
946 | ev_timer_again (loop, timer); |
948 | ev_timer_again (loop, timer); |
947 | |
949 | |
948 | This is more efficient then stopping/starting the timer eahc time you want |
950 | This is more slightly efficient then stopping/starting the timer each time |
949 | to modify its timeout value. |
951 | you want to modify its timeout value. |
950 | |
952 | |
951 | =item ev_tstamp repeat [read-write] |
953 | =item ev_tstamp repeat [read-write] |
952 | |
954 | |
953 | The current C<repeat> value. Will be used each time the watcher times out |
955 | The current C<repeat> value. Will be used each time the watcher times out |
954 | or C<ev_timer_again> is called and determines the next timeout (if any), |
956 | or C<ev_timer_again> is called and determines the next timeout (if any), |