[Click] Element::selected()
Eddie Kohler
kohler at cs.ucla.edu
Tue Mar 2 20:12:46 EST 2010
Hi Ian,
It's this way because even if a file descriptor was selected for both reading
and writing, selected() is called only once.
It might be useful to say whether reading or writing was enabled...but of
course in between select()'s return and the call of selected(), something
might have happened to make the fd selectable in other ways. I don't feel
that strongly.
Eddie
Ian Rose wrote:
> Hi list,
>
> Is there any rational for why Element::selected() doesn't tell you what
> the file descriptor was selected for (reading vs. writing)? Or is there
> a way to get this info that I don't know about? It seems to me that if
> you have a FD that you are both reading and writing to (like a socket)
> you are pretty much stuck with something like:
>
> void
> Foo::selected(int fd)
> {
> // perhaps fd was selected for writes...
> int rv = send(fd, ...);
> if (rv == -1) {
> if (errno == EAGAIN) {
> // oops - I guess fd was actually selected for reads
> int rv = recv(fd, ...);
> (etc)
> } else {
> // this is a "real" send failure
> }
> }
> // send succeeded!
> (etc)
> }
>
> Seems kinda ugly and inefficient to me... Am I missing something?
>
> I guess an alternative is to call select() on your fd to figure out
> which it was selected for, but that's rather redundant!
>
> - Ian
>
>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
More information about the click
mailing list