[Freeswitch-users] Detecting End of Content on Socket Interface
Anthony Minessale
anthony.minessale at gmail.com
Wed Oct 22 10:13:00 EDT 2008
As soon as the socket reads even one byte of input it will never send any
events until it has fully parsed the input packet and replied to it. In the
unlikely event of an event being delivered over the socket with perfect
timing to be received as soon as you put in a command you would have to
cache that event and continue reading until you got your reply. You can
count on the fact that you will never get the wrong reply over the socket as
it will never allow anything else to happen until it deals with the current
input.
In my perl client in tree just to be safe i serialize and cache any events
that may be received during the waiting for a reply to a command. Like I
said all events will be stopped until you get the command reply, they are
being cached in a fifo and will all come over the wire as soon as the
command is completed. This allows you to execute commands where you
intentionally want to block until you get the answer and in cases where you
don't want that you can use the bgapi command to launch the command in a
thread and have it return instantly.
On Wed, Oct 22, 2008 at 8:42 AM, Klaus Teller <klaus.teller at gmx.net> wrote:
> Hi,
>
> I have a pretty silly question here, so please bear with me. When reading
> events through a socket (socket event interface), it is said that i should
> either wait for 2CR or if the content length was specified, i must continue
> reading until i got the exact number of bytes from the input stream.
>
> Now, what happens when reading simple responses such as:
>
> Request response: Content-Type: command/reply
> Reply-Text: +OK
>
> Is there a way to detect the end of such blocks?
>
> The issue i have is following. Given that events are asynchronous (please
> correct me if i'm wrong), i need a thread which continuously read and
> process them as they arrive. But then, considering that not only events are
> sent by Freeswitch, i want to also detect different response commands
> properly.
>
> Let me give an example. I send a command to Freeswitch to play a file.
> Right after that, i wait for the answer from Freeswitch. But just before the
> response, Freeswitch could send a DTMF event. If i use a dedicated reading
> thread, how does it identify the response that resulted from the play file
> command? Otherwise, if i try to synchronously wait for the result just
> after sending the play file command, how do i say that what i will get from
> Freeswitch is not just the part of an event?
>
> Does this make any sense to you?
>
> Thanks,
> Klaus.
>
> --
> "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
> Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
>
> _______________________________________________
> Freeswitch-users mailing list
> Freeswitch-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
--
Anthony Minessale II
FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
AIM: anthm
MSN:anthony_minessale at hotmail.com <MSN%3Aanthony_minessale at hotmail.com>
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com<PAYPAL%3Aanthony.minessale at gmail.com>
IRC: irc.freenode.net #freeswitch
FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org <sip%3A888 at conference.freeswitch.org>
iax:guest at conference.freeswitch.org/888
googletalk:conf+888 at conference.freeswitch.org<googletalk%3Aconf%2B888 at conference.freeswitch.org>
pstn:213-799-1400
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20081022/95c3edc4/attachment-0001.html
More information about the Freeswitch-users
mailing list