X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/f432e03e319f1ece247021aa0810c4af1cb50042..22b2a449105d7604f715c1afafeb4fe5ac473f1b:/ev_select.c?ds=sidebyside diff --git a/ev_select.c b/ev_select.c index 46a77e2..9f81e55 100644 --- a/ev_select.c +++ b/ev_select.c @@ -1,4 +1,6 @@ /* + * libev select fd activity backend + * * Copyright (c) 2007 Marc Alexander Lehmann * All rights reserved. * @@ -33,20 +35,22 @@ #include /* for unix systems */ -#include +#ifndef WIN32 +# include +#endif #include #include -static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo; -static int vec_max; - static void -select_modify (int fd, int oev, int nev) +select_modify (EV_P_ int fd, int oev, int nev) { int offs = fd >> 3; int mask = 1 << (fd & 7); + if (oev == nev) + return; + if (vec_max < (fd >> 5) + 1) { int new_max = (fd >> 5) + 1; @@ -70,7 +74,8 @@ select_modify (int fd, int oev, int nev) vec_wi [offs] &= ~mask; } -static void select_poll (ev_tstamp timeout) +static void +select_poll (EV_P_ ev_tstamp timeout) { struct timeval tv; int res; @@ -105,7 +110,7 @@ static void select_poll (ev_tstamp timeout) events |= byte_w & (1 << bit) ? EV_WRITE : 0; if (events) - fd_event (idx * 8 + bit, events); + fd_event (EV_A_ idx * 8 + bit, events); } } } @@ -113,16 +118,35 @@ static void select_poll (ev_tstamp timeout) else if (res < 0) { if (errno == EBADF) - fd_recheck (); + fd_ebadf (EV_A); + else if (errno == ENOMEM) + fd_enomem (EV_A); } } -void select_init (int flags) +static int +select_init (EV_P_ int flags) { - ev_method = EVMETHOD_SELECT; method_fudge = 1e-2; /* needed to compensate for select returning early, very conservative */ method_modify = select_modify; method_poll = select_poll; + + vec_max = 0; + vec_ri = 0; + vec_ri = 0; + vec_wo = 0; + vec_wo = 0; + + return EVMETHOD_SELECT; +} + +static void +select_destroy (EV_P) +{ + free (vec_ri); + free (vec_ro); + free (vec_wi); + free (vec_wo); }