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

Comparing libev/ev.c (file contents):
Revision 1.43 by root, Fri Nov 2 20:21:33 2007 UTC vs.
Revision 1.46 by root, Sat Nov 3 09:20:12 2007 UTC

42#include <stdio.h> 42#include <stdio.h>
43 43
44#include <assert.h> 44#include <assert.h>
45#include <errno.h> 45#include <errno.h>
46#include <sys/types.h> 46#include <sys/types.h>
47#ifndef WIN32
47#include <sys/wait.h> 48# include <sys/wait.h>
49#endif
48#include <sys/time.h> 50#include <sys/time.h>
49#include <time.h> 51#include <time.h>
50 52
51/**/ 53/**/
52 54
62# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ 64# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */
63#endif 65#endif
64 66
65#ifndef EV_USE_EPOLL 67#ifndef EV_USE_EPOLL
66# define EV_USE_EPOLL 0 68# define EV_USE_EPOLL 0
69#endif
70
71#ifndef EV_USE_KQUEUE
72# define EV_USE_KQUEUE 0
67#endif 73#endif
68 74
69#ifndef EV_USE_REALTIME 75#ifndef EV_USE_REALTIME
70# define EV_USE_REALTIME 1 76# define EV_USE_REALTIME 1
71#endif 77#endif
434} 440}
435 441
436static void 442static void
437siginit (void) 443siginit (void)
438{ 444{
445#ifndef WIN32
439 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); 446 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC);
440 fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC); 447 fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
441 448
442 /* rather than sort out wether we really need nb, set it */ 449 /* rather than sort out wether we really need nb, set it */
443 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 450 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
444 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 451 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
452#endif
445 453
446 ev_io_set (&sigev, sigpipe [0], EV_READ); 454 ev_io_set (&sigev, sigpipe [0], EV_READ);
447 ev_io_start (&sigev); 455 ev_io_start (&sigev);
448} 456}
449 457
460 468
461/*****************************************************************************/ 469/*****************************************************************************/
462 470
463static struct ev_child *childs [PID_HASHSIZE]; 471static struct ev_child *childs [PID_HASHSIZE];
464static struct ev_signal childev; 472static struct ev_signal childev;
473
474#ifndef WIN32
465 475
466#ifndef WCONTINUED 476#ifndef WCONTINUED
467# define WCONTINUED 0 477# define WCONTINUED 0
468#endif 478#endif
469 479
475 485
476 while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) 486 while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1)
477 for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) 487 for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next)
478 if (w->pid == pid || !w->pid) 488 if (w->pid == pid || !w->pid)
479 { 489 {
490 w->rpid = pid;
480 w->status = status; 491 w->rstatus = status;
481 event ((W)w, EV_CHILD); 492 event ((W)w, EV_CHILD);
482 } 493 }
483} 494}
484 495
485/*****************************************************************************/ 496#endif
486 497
498/*****************************************************************************/
499
500#if EV_USE_KQUEUE
501# include "ev_kqueue.c"
502#endif
487#if EV_USE_EPOLL 503#if EV_USE_EPOLL
488# include "ev_epoll.c" 504# include "ev_epoll.c"
489#endif 505#endif
490#if EV_USE_POLL 506#if EV_USE_POLL
491# include "ev_poll.c" 507# include "ev_poll.c"
539 methods = atoi (getenv ("LIBEV_METHODS")); 555 methods = atoi (getenv ("LIBEV_METHODS"));
540 else 556 else
541 methods = EVMETHOD_ANY; 557 methods = EVMETHOD_ANY;
542 558
543 ev_method = 0; 559 ev_method = 0;
560#if EV_USE_KQUEUE
561 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods);
562#endif
544#if EV_USE_EPOLL 563#if EV_USE_EPOLL
545 if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); 564 if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods);
546#endif 565#endif
547#if EV_USE_POLL 566#if EV_USE_POLL
548 if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods); 567 if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods);
554 if (ev_method) 573 if (ev_method)
555 { 574 {
556 ev_watcher_init (&sigev, sigcb); 575 ev_watcher_init (&sigev, sigcb);
557 siginit (); 576 siginit ();
558 577
578#ifndef WIN32
559 ev_signal_init (&childev, childcb, SIGCHLD); 579 ev_signal_init (&childev, childcb, SIGCHLD);
560 ev_signal_start (&childev); 580 ev_signal_start (&childev);
581#endif
561 } 582 }
562 } 583 }
563 584
564 return ev_method; 585 return ev_method;
565} 586}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines