[Click] Element::selected()
Ian Rose
ianrose at eecs.harvard.edu
Tue Mar 2 19:59:21 EST 2010
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
More information about the click
mailing list