[asterisk-dev] Question about the code in __ast_request_and_dial()

Tony Mountifield tony at softins.clara.co.uk
Tue Feb 21 11:21:29 MST 2006

I am experimenting with a channel that I set to Up as soon as a call
is initiated on it. Normal calls to this channel from another phone
work fine.

The problem I have is when trying to initiated a call to this channel
from a .call file, and I've tracked it down to __ast_request_and_dial()
in channel.c.

At the beginning of the function, res is initialized to 0.

If ast_call() succeeds by returning zero, control enters a loop which
waits for AST_STATE_UP with a timeout. Inside the loop, res gets set
by ast_waitfor().

At the end of the function, after setting outstate, there is the test:

if (chan && res <= 0)

The problem I have is that if the channel state is AST_STATE_UP the
very first time it is tested, control reaches that test with res=0
and the channel immediately gets hung up again.

I'm assuming there is a reason the test is "res <= 0" and not "res < 0".
Is this correct?

I think I could solve my problem by putting a "res = 1;" just before
the while loop that waits for AST_STATE_UP.

I just want a sanity check really, to make sure I haven't overlooked
something that will come back to bite me!

Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org

More information about the asterisk-dev mailing list