Cancel read on socket

Leon Pollak leonp at plris.com
Wed May 28 07:44:54 UTC 2008


On Wednesday, 28 בMay 2008, Paul Whitfield wrote:
>
> If you have don't want/need a timeout you could modify your
> code to make use of a SO_RCVWAKEUP callback.
>
> You could create a callback that sends an event to the waiting task.
> To cancel send a different event to the waiting task
>
> Paul ...
>
> It goes something like this (error handling removed):
>
> /* To install the callback */
> struct sockwakeup wakeup;
> wakeup.sw_pfn = callback;
> wakeup.sw_arg = (caddr_t ) fd;
> setsockopt(fd, SOL_SOCKET, SO_RCVWAKEUP, &wakeup, sizeof(wakeup));
> /* The callback */
> void callback(struct socket *so, caddr_t arg)
> {
>     rtems_event_send( task, EVENT_UDP_RX );
> }
> /* The Cancel function */
> void cancel_udp_wait(void )
> {
>     rtems_event_send(task, EVENT_UDP_CANCEL);
> }
> /* The Application Code */
>     rtems_event_receive(  EVENT_UDP_RX | EVENT_UDP_CANCEL ,
> 		RTEMS_EVENT_ANY | RTEMS_WAIT,
> 		RTEMS_NO_TIMEOUT,
> 		&event);
>     if ( event & EVENT_UDP_RX )
>     {
>         // Read and Process
>     }
>     if ( event & EVENT_UDP_CANCEL )
>     {
>         // Do Cancel processing
>     }
Thank you, Paul for this - I did not know about this option.
Although this is an interesting variant, it still suffers from the same 
problem - relatively large overhead for the very simple operation.

Also in your suggestion, I need to call rtems_event_receive() routine (which 
takes significant time) on EACH packet reception, while actually it will fall 
into cancel event only once per 1 million packets.


Thanks again - interesting feature I did not know.
-- 
Leon



More information about the users mailing list