Bug in select_modify?

Matt Tolton matt at tolton.com
Sun Jun 8 10:24:31 CEST 2008


Hi,

In getting libev running on windows, I think I may have found a bug in
the select_modify() function in ev_select.c.  Apparently windows uses
an array for its fd set, and it doesn't check to see if the fd is
already in the set when you do an FD_SET.  This causes libev to put
duplicates in the set, and only one would get cleared when FD_CLR was
used.  This caused libev to go into an endless loop because select()
kept returning EBADF, but libev couldn't find the bad fd.  I imagine
that most fd sets use bitvectors or something so this isn't a problem
(not that I know much about this stuff).  I made the following
modification to select_modify (sorry it's not in diff format...I'm
sure you can see where it goes):

	if (nev & EV_READ) {
      if (!(oev & EV_READ))
		  FD_SET (handle, (fd_set *)vec_ri);
	} else {
      FD_CLR (handle, (fd_set *)vec_ri);
	}

	if (nev & EV_WRITE) {
      if (!(oev & EV_WRITE))
		  FD_SET (handle, (fd_set *)vec_wi);
	} else {
      FD_CLR (handle, (fd_set *)vec_wi);
	}

It seems that something like this should be added to the real libev
source.  You could also, of course, use the FD_ISSET macro.  This
would probably be more foolproof, but I'm guessing it would be slower
(not that we'll get much performance out of windows using select()
anyway).

Thanks,

Matt



More information about the libev mailing list