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

Comparing libev/ev.c (file contents):
Revision 1.253 by root, Sat May 31 03:13:27 2008 UTC vs.
Revision 1.263 by root, Wed Oct 1 18:50:03 2008 UTC

154#ifndef _WIN32 154#ifndef _WIN32
155# include <sys/time.h> 155# include <sys/time.h>
156# include <sys/wait.h> 156# include <sys/wait.h>
157# include <unistd.h> 157# include <unistd.h>
158#else 158#else
159# include <io.h>
159# define WIN32_LEAN_AND_MEAN 160# define WIN32_LEAN_AND_MEAN
160# include <windows.h> 161# include <windows.h>
161# ifndef EV_SELECT_IS_WINSOCKET 162# ifndef EV_SELECT_IS_WINSOCKET
162# define EV_SELECT_IS_WINSOCKET 1 163# define EV_SELECT_IS_WINSOCKET 1
163# endif 164# endif
286# endif 287# endif
287#endif 288#endif
288 289
289#if EV_USE_INOTIFY 290#if EV_USE_INOTIFY
290# include <sys/inotify.h> 291# include <sys/inotify.h>
292/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
293# ifndef IN_DONT_FOLLOW
294# undef EV_USE_INOTIFY
295# define EV_USE_INOTIFY 0
296# endif
291#endif 297#endif
292 298
293#if EV_SELECT_IS_WINSOCKET 299#if EV_SELECT_IS_WINSOCKET
294# include <winsock.h> 300# include <winsock.h>
295#endif 301#endif
564 struct timeval tv; 570 struct timeval tv;
565 571
566 tv.tv_sec = (time_t)delay; 572 tv.tv_sec = (time_t)delay;
567 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); 573 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6);
568 574
575 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
576 /* somehting nto guaranteed by newer posix versions, but guaranteed */
577 /* by older ones */
569 select (0, 0, 0, 0, &tv); 578 select (0, 0, 0, 0, &tv);
570#endif 579#endif
571 } 580 }
572} 581}
573 582
707 events |= (unsigned char)w->events; 716 events |= (unsigned char)w->events;
708 717
709#if EV_SELECT_IS_WINSOCKET 718#if EV_SELECT_IS_WINSOCKET
710 if (events) 719 if (events)
711 { 720 {
712 unsigned long argp; 721 unsigned long arg;
713 #ifdef EV_FD_TO_WIN32_HANDLE 722 #ifdef EV_FD_TO_WIN32_HANDLE
714 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); 723 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
715 #else 724 #else
716 anfd->handle = _get_osfhandle (fd); 725 anfd->handle = _get_osfhandle (fd);
717 #endif 726 #endif
718 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); 727 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
719 } 728 }
720#endif 729#endif
721 730
722 { 731 {
723 unsigned char o_events = anfd->events; 732 unsigned char o_events = anfd->events;
776{ 785{
777 int fd; 786 int fd;
778 787
779 for (fd = 0; fd < anfdmax; ++fd) 788 for (fd = 0; fd < anfdmax; ++fd)
780 if (anfds [fd].events) 789 if (anfds [fd].events)
781 if (!fd_valid (fd) == -1 && errno == EBADF) 790 if (!fd_valid (fd) && errno == EBADF)
782 fd_kill (EV_A_ fd); 791 fd_kill (EV_A_ fd);
783} 792}
784 793
785/* called on ENOMEM in select/poll to kill some fds and retry */ 794/* called on ENOMEM in select/poll to kill some fds and retry */
786static void noinline 795static void noinline
983 992
984void inline_speed 993void inline_speed
985fd_intern (int fd) 994fd_intern (int fd)
986{ 995{
987#ifdef _WIN32 996#ifdef _WIN32
988 int arg = 1; 997 unsigned long arg = 1;
989 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 998 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
990#else 999#else
991 fcntl (fd, F_SETFD, FD_CLOEXEC); 1000 fcntl (fd, F_SETFD, FD_CLOEXEC);
992 fcntl (fd, F_SETFL, O_NONBLOCK); 1001 fcntl (fd, F_SETFL, O_NONBLOCK);
993#endif 1002#endif
1507{ 1516{
1508 postfork = 1; /* must be in line with ev_default_fork */ 1517 postfork = 1; /* must be in line with ev_default_fork */
1509} 1518}
1510 1519
1511#if EV_VERIFY 1520#if EV_VERIFY
1512void noinline 1521static void noinline
1513verify_watcher (EV_P_ W w) 1522verify_watcher (EV_P_ W w)
1514{ 1523{
1515 assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 1524 assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
1516 1525
1517 if (w->pending) 1526 if (w->pending)
1905ev_unref (EV_P) 1914ev_unref (EV_P)
1906{ 1915{
1907 --activecnt; 1916 --activecnt;
1908} 1917}
1909 1918
1919void
1920ev_now_update (EV_P)
1921{
1922 time_update (EV_A_ 1e100);
1923}
1924
1910static int loop_done; 1925static int loop_done;
1911 1926
1912void 1927void
1913ev_loop (EV_P_ int flags) 1928ev_loop (EV_P_ int flags)
1914{ 1929{
2567 } 2582 }
2568 2583
2569 } 2584 }
2570} 2585}
2571 2586
2587#endif
2588
2589#ifdef _WIN32
2590# define EV_LSTAT(p,b) _stati64 (p, b)
2591#else
2592# define EV_LSTAT(p,b) lstat (p, b)
2572#endif 2593#endif
2573 2594
2574void 2595void
2575ev_stat_stat (EV_P_ ev_stat *w) 2596ev_stat_stat (EV_P_ ev_stat *w)
2576{ 2597{
2817 ev_loop (EV_A_ EVLOOP_NONBLOCK); 2838 ev_loop (EV_A_ EVLOOP_NONBLOCK);
2818 } 2839 }
2819 } 2840 }
2820} 2841}
2821 2842
2843static void
2844embed_fork_cb (EV_P_ ev_fork *fork_w, int revents)
2845{
2846 ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork));
2847
2848 {
2849 struct ev_loop *loop = w->other;
2850
2851 ev_loop_fork (EV_A);
2852 }
2853}
2854
2822#if 0 2855#if 0
2823static void 2856static void
2824embed_idle_cb (EV_P_ ev_idle *idle, int revents) 2857embed_idle_cb (EV_P_ ev_idle *idle, int revents)
2825{ 2858{
2826 ev_idle_stop (EV_A_ idle); 2859 ev_idle_stop (EV_A_ idle);
2846 2879
2847 ev_prepare_init (&w->prepare, embed_prepare_cb); 2880 ev_prepare_init (&w->prepare, embed_prepare_cb);
2848 ev_set_priority (&w->prepare, EV_MINPRI); 2881 ev_set_priority (&w->prepare, EV_MINPRI);
2849 ev_prepare_start (EV_A_ &w->prepare); 2882 ev_prepare_start (EV_A_ &w->prepare);
2850 2883
2884 ev_fork_init (&w->fork, embed_fork_cb);
2885 ev_fork_start (EV_A_ &w->fork);
2886
2851 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ 2887 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/
2852 2888
2853 ev_start (EV_A_ (W)w, 1); 2889 ev_start (EV_A_ (W)w, 1);
2854 2890
2855 EV_FREQUENT_CHECK; 2891 EV_FREQUENT_CHECK;
2862 if (expect_false (!ev_is_active (w))) 2898 if (expect_false (!ev_is_active (w)))
2863 return; 2899 return;
2864 2900
2865 EV_FREQUENT_CHECK; 2901 EV_FREQUENT_CHECK;
2866 2902
2867 ev_io_stop (EV_A_ &w->io); 2903 ev_io_stop (EV_A_ &w->io);
2868 ev_prepare_stop (EV_A_ &w->prepare); 2904 ev_prepare_stop (EV_A_ &w->prepare);
2869 2905 ev_fork_stop (EV_A_ &w->fork);
2870 ev_stop (EV_A_ (W)w);
2871 2906
2872 EV_FREQUENT_CHECK; 2907 EV_FREQUENT_CHECK;
2873} 2908}
2874#endif 2909#endif
2875 2910
2972once_cb (EV_P_ struct ev_once *once, int revents) 3007once_cb (EV_P_ struct ev_once *once, int revents)
2973{ 3008{
2974 void (*cb)(int revents, void *arg) = once->cb; 3009 void (*cb)(int revents, void *arg) = once->cb;
2975 void *arg = once->arg; 3010 void *arg = once->arg;
2976 3011
2977 ev_io_stop (EV_A_ &once->io); 3012 ev_io_stop (EV_A_ &once->io);
2978 ev_timer_stop (EV_A_ &once->to); 3013 ev_timer_stop (EV_A_ &once->to);
2979 ev_free (once); 3014 ev_free (once);
2980 3015
2981 cb (revents, arg); 3016 cb (revents, arg);
2982} 3017}
2983 3018
2984static void 3019static void
2985once_cb_io (EV_P_ ev_io *w, int revents) 3020once_cb_io (EV_P_ ev_io *w, int revents)
2986{ 3021{
2987 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); 3022 struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io));
3023
3024 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->to));
2988} 3025}
2989 3026
2990static void 3027static void
2991once_cb_to (EV_P_ ev_timer *w, int revents) 3028once_cb_to (EV_P_ ev_timer *w, int revents)
2992{ 3029{
2993 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); 3030 struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to));
3031
3032 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
2994} 3033}
2995 3034
2996void 3035void
2997ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 3036ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
2998{ 3037{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines