ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.402 by root, Wed Apr 18 06:09:29 2012 UTC vs.
Revision 1.403 by sf-exg, Wed Apr 18 06:56:53 2012 UTC

1874 callback (EV_P_ ev_timer *w, int revents) 1874 callback (EV_P_ ev_timer *w, int revents)
1875 { 1875 {
1876 // calculate when the timeout would happen 1876 // calculate when the timeout would happen
1877 ev_tstamp after = last_activity - ev_now (EV_A) + timeout; 1877 ev_tstamp after = last_activity - ev_now (EV_A) + timeout;
1878 1878
1879 // if negative, it means we the timeout already occured 1879 // if negative, it means we the timeout already occurred
1880 if (after < 0.) 1880 if (after < 0.)
1881 { 1881 {
1882 // timeout occurred, take action 1882 // timeout occurred, take action
1883 } 1883 }
1884 else 1884 else
1902 1902
1903Otherwise, we now the earliest time at which the timeout would trigger, 1903Otherwise, we now the earliest time at which the timeout would trigger,
1904and simply start the timer with this timeout value. 1904and simply start the timer with this timeout value.
1905 1905
1906In other words, each time the callback is invoked it will check whether 1906In other words, each time the callback is invoked it will check whether
1907the timeout cocured. If not, it will simply reschedule itself to check 1907the timeout occurred. If not, it will simply reschedule itself to check
1908again at the earliest time it could time out. Rinse. Repeat. 1908again at the earliest time it could time out. Rinse. Repeat.
1909 1909
1910This scheme causes more callback invocations (about one every 60 seconds 1910This scheme causes more callback invocations (about one every 60 seconds
1911minus half the average time between activity), but virtually no calls to 1911minus half the average time between activity), but virtually no calls to
1912libev to change the timeout. 1912libev to change the timeout.
1926 if (activity detected) 1926 if (activity detected)
1927 last_activity = ev_now (EV_A); 1927 last_activity = ev_now (EV_A);
1928 1928
1929When your timeout value changes, then the timeout can be changed by simply 1929When your timeout value changes, then the timeout can be changed by simply
1930providing a new value, stopping the timer and calling the callback, which 1930providing a new value, stopping the timer and calling the callback, which
1931will agaion do the right thing (for example, time out immediately :). 1931will again do the right thing (for example, time out immediately :).
1932 1932
1933 timeout = new_value; 1933 timeout = new_value;
1934 ev_timer_stop (EV_A_ &timer); 1934 ev_timer_stop (EV_A_ &timer);
1935 callback (EV_A_ &timer, 0); 1935 callback (EV_A_ &timer, 0);
1936 1936
3921 3921
3922 ... 3922 ...
3923 ev_set_syserr_cb (fatal_error); 3923 ev_set_syserr_cb (fatal_error);
3924 3924
3925The only API functions that can currently throw exceptions are C<ev_run>, 3925The only API functions that can currently throw exceptions are C<ev_run>,
3926C<ev_inoke>, C<ev_invoke_pending> and C<ev_loop_destroy> (the latter 3926C<ev_invoke>, C<ev_invoke_pending> and C<ev_loop_destroy> (the latter
3927because it runs cleanup watchers). 3927because it runs cleanup watchers).
3928 3928
3929Throwing exceptions in watcher callbacks is only supported if libev itself 3929Throwing exceptions in watcher callbacks is only supported if libev itself
3930is compiled with a C++ compiler or your C and C++ environments allow 3930is compiled with a C++ compiler or your C and C++ environments allow
3931throwing exceptions through C libraries (most do). 3931throwing exceptions through C libraries (most do).

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines