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

Comparing libev/ev.c (file contents):
Revision 1.49 by root, Sat Nov 3 16:16:58 2007 UTC vs.
Revision 1.50 by root, Sat Nov 3 19:41:55 2007 UTC

26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#if EV_USE_CONFIG_H 31#ifndef EV_STANDALONE
32# include "config.h" 32# include "config.h"
33#endif 33#endif
34 34
35#include <math.h> 35#include <math.h>
36#include <stdlib.h> 36#include <stdlib.h>
175 175
176/*****************************************************************************/ 176/*****************************************************************************/
177 177
178typedef struct 178typedef struct
179{ 179{
180 struct ev_io *head; 180 struct ev_watcher_list *head;
181 unsigned char events; 181 unsigned char events;
182 unsigned char reify; 182 unsigned char reify;
183} ANFD; 183} ANFD;
184 184
185static ANFD *anfds; 185static ANFD *anfds;
235fd_event (int fd, int events) 235fd_event (int fd, int events)
236{ 236{
237 ANFD *anfd = anfds + fd; 237 ANFD *anfd = anfds + fd;
238 struct ev_io *w; 238 struct ev_io *w;
239 239
240 for (w = anfd->head; w; w = w->next) 240 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
241 { 241 {
242 int ev = w->events & events; 242 int ev = w->events & events;
243 243
244 if (ev) 244 if (ev)
245 event ((W)w, ev); 245 event ((W)w, ev);
262 ANFD *anfd = anfds + fd; 262 ANFD *anfd = anfds + fd;
263 struct ev_io *w; 263 struct ev_io *w;
264 264
265 int events = 0; 265 int events = 0;
266 266
267 for (w = anfd->head; w; w = w->next) 267 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
268 events |= w->events; 268 events |= w->events;
269 269
270 anfd->reify = 0; 270 anfd->reify = 0;
271 271
272 if (anfd->events != events) 272 if (anfd->events != events)
295static void 295static void
296fd_kill (int fd) 296fd_kill (int fd)
297{ 297{
298 struct ev_io *w; 298 struct ev_io *w;
299 299
300 printf ("killing fd %d\n", fd);//D
301 while ((w = anfds [fd].head)) 300 while ((w = (struct ev_io *)anfds [fd].head))
302 { 301 {
303 ev_io_stop (w); 302 ev_io_stop (w);
304 event ((W)w, EV_ERROR | EV_READ | EV_WRITE); 303 event ((W)w, EV_ERROR | EV_READ | EV_WRITE);
305 } 304 }
306} 305}
383 382
384/*****************************************************************************/ 383/*****************************************************************************/
385 384
386typedef struct 385typedef struct
387{ 386{
388 struct ev_signal *head; 387 struct ev_watcher_list *head;
389 sig_atomic_t volatile gotsig; 388 sig_atomic_t volatile gotsig;
390} ANSIG; 389} ANSIG;
391 390
392static ANSIG *signals; 391static ANSIG *signals;
393static int signalmax; 392static int signalmax;
423} 422}
424 423
425static void 424static void
426sigcb (struct ev_io *iow, int revents) 425sigcb (struct ev_io *iow, int revents)
427{ 426{
428 struct ev_signal *w; 427 struct ev_watcher_list *w;
429 int signum; 428 int signum;
430 429
431 read (sigpipe [0], &revents, 1); 430 read (sigpipe [0], &revents, 1);
432 gotsig = 0; 431 gotsig = 0;
433 432
482static void 481static void
483child_reap (struct ev_signal *sw, int chain, int pid, int status) 482child_reap (struct ev_signal *sw, int chain, int pid, int status)
484{ 483{
485 struct ev_child *w; 484 struct ev_child *w;
486 485
487 for (w = childs [chain & (PID_HASHSIZE - 1)]; w; w = w->next) 486 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
488 if (w->pid == pid || !w->pid) 487 if (w->pid == pid || !w->pid)
489 { 488 {
490 w->priority = sw->priority; /* need to do it *now* */ 489 w->priority = sw->priority; /* need to do it *now* */
491 w->rpid = pid; 490 w->rpid = pid;
492 w->rstatus = status; 491 w->rstatus = status;
493 printf ("rpid %p %d %d\n", w, pid, w->pid);//D
494 event ((W)w, EV_CHILD); 492 event ((W)w, EV_CHILD);
495 } 493 }
496} 494}
497 495
498static void 496static void
499childcb (struct ev_signal *sw, int revents) 497childcb (struct ev_signal *sw, int revents)
500{ 498{
501 int pid, status; 499 int pid, status;
502 500
503 printf ("chld %x\n", revents);//D
504 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 501 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
505 { 502 {
506 /* make sure we are called again until all childs have been reaped */ 503 /* make sure we are called again until all childs have been reaped */
507 event ((W)sw, EV_SIGNAL); 504 event ((W)sw, EV_SIGNAL);
508 505
571 568
572 if (pipe (sigpipe)) 569 if (pipe (sigpipe))
573 return 0; 570 return 0;
574 571
575 if (methods == EVMETHOD_AUTO) 572 if (methods == EVMETHOD_AUTO)
576 if (!enable_secure () && getenv ("LIBEV_METHODS")) 573 if (!enable_secure () && getenv ("LIBEV_METHODS"))
577 methods = atoi (getenv ("LIBEV_METHODS")); 574 methods = atoi (getenv ("LIBEV_METHODS"));
578 else 575 else
579 methods = EVMETHOD_ANY; 576 methods = EVMETHOD_ANY;
580 577
581 ev_method = 0; 578 ev_method = 0;
582#if EV_USE_KQUEUE 579#if EV_USE_KQUEUE
583 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods); 580 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods);
584#endif 581#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines