[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Cancel read on socket
- Date: Wed, 28 May 2008 10:44:54 +0300
- From: leonp at plris.com (Leon Pollak)
- Subject: Cancel read on socket
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,
> 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.