[Click] Element::selected()

Ian Rose ianrose at eecs.harvard.edu
Wed Mar 3 13:34:48 EST 2010


Thanks!  That was impressively speedy.


Eddie Kohler wrote:
> Yeah, point taken.  The new interface is checked in!
> 
> Eddie
> 
> 
> Ian Rose wrote:
>>
>> Eddie Kohler wrote:
>>> Hi Ian,
>>>
>>> It's this way because even if a file descriptor was selected for both 
>>> reading and writing, selected() is called only once.
>>
>> True, but you could just use flags right?  So the function could be 
>> redefined as Element::selected(int fd, int ops)
>>
>> and called like
>> elt->selected(fd, Element::SELECT_READ)
>> or elt->selected(fd, Element::SELECT_WRITE)
>> or elt->selected(fd, Element::SELECT_READ | Element::SELECT_WRITE)
>>
>>>
>>> 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.  
>>
>> Also true, but if it was really that important to someone, they could 
>> always do that re-checking themselves.  E.g. if their selected() was 
>> called for reading, they could also check the fd for writing "just in 
>> case".  That seems rather inefficient to me, but I guess there could 
>> be some apps that really want to know ASAP when the fd is ready.
>>
>>> I don't feel that strongly.
>>
>> I think that adding a second function something like the following 
>> would retain existing functionality - do you agree?
>>
>> (in element.hh)
>> virtual void selected(int fd, int ops);
>>
>> (in element.cc)
>> void
>> Element::selected(int fd, int ops)
>> {
>>     selected(fd);
>> }
>>
>>
>>>
>>> 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