Cancel read on socket
Leon Pollak
leonp at plris.com
Tue May 27 13:59:53 UTC 2008
On Tuesday, 27 בMay 2008, Torsten Landschoff wrote:
> Leon Pollak wrote:
> > Is there any way to cancel currently waiting read operation on UDP
> > socket? I do not want to close it (need to use it immediately) or use
> > select() (consumes a lot of CPU time).
>
> Why does select() consume a lot of CPU time!?
Just look into the code...
Well, everything in this world is relative...:-)
The code has a lot of operations, even rtems calls...
> Wouldn't it be obvious to
> fix select() then? Or poll for that matter...
I do not think the select needs fixing - it does fine what it should do...
> AFAIK, the standard approach is to use a non-blocking socket, try a read
> and only use select() if no data was available.
My case is simple: other side sends A LOT of data all the time. Then, once
upon a time from another task I send it "stop". The receiving task hangs
on 'read', while I need it to exit from read, do something and return back.
I do not want to waste the CPU for 99% unnecessary work doing select() or
checking asynchronous ready.
The Joel's suggestion will allow to solve the issue with just one 'if'
operator.
> Sorry for not knowing a better/tested solution...
> Torsten
Thanks for your willing to help.
--
Leon
More information about the users
mailing list