[asterisk-dev] ast_read and frames of type AST_FRAME_NULL?

Russell Bryant russell at digium.com
Tue Jun 22 18:12:03 CDT 2010


On 06/22/2010 05:58 PM, Bryan Field-Elliot wrote:
> We have a custom app (for Asterisk 1.6.2.6) which needs to wait for certain events on a SIP channel.
>
> Our code, briefly, looks like the following:
>
> for (;;) {
> 	r = ast_waitfor(chan, 100)
> 	if (r<  0) break;
> 	frame = ast_read(chan);
> 	if (frame->frametype == AST_FRAME_NULL) {
> 		usleep(10);
> 		continue;
> 	}
> }
>
> What we are finding is that under normal load, we get hundreds of AST_FRAME_NULL's out of ast_read, and it would be in the hundreds of thousands if not for the usleep() command to yield some cycles to other threads.
>
> My question for the group is -- what are we doing wrong? It seems like lots of CPU cycles are being wasted here, creating and then discarding AST_FRAME_NULL's. Do they serve a hidden purpose? If not, is there something else we can do to have ast_waitfor and ast_read truly only return when they have some interesting data to tell us about?

Your timeout to ast_waitfor() is 100ms.  As it is written, you will be 
calling ast_read() on the channel every time it times out, and not just 
when you're actually supposed to.

-- 
Russell Bryant
Digium, Inc.  |  Engineering Manager, Open Source Software
445 Jan Davis Drive NW   -    Huntsville, AL 35806  -  USA
jabber: rbryant at digium.com    -=-    skype: russell-bryant
www.digium.com -=- www.asterisk.org -=- blogs.asterisk.org



More information about the asterisk-dev mailing list