Subject: Re: Callback for channel data ready

Re: Callback for channel data ready

From: Tom Weber <tom.weber_at_cryptzone.com>
Date: Mon, 12 Mar 2012 11:15:45 +0100

Tom Weber skrev 3/12/12 10:58 AM:
> Another question regarding the channel data queue. Is there a risk that
> we could miss incoming data which is received during the query-loop?
> Imagine the following situation:
>
> 1. poll() indicates POLLIN on the session socket.
>
> 2. The application checks channel #1, no data is waiting.
>
> 3. The application checks channel #2, no data is waiting, but libssh2
> receives data for channel #1.
>
> 4. poll() sits around waiting, while we need the channel #1 data to
> carry on the conversation.
>
> We have seen delays in traffic now and then, and I wonder if this is the
> reason. If so, can you recommend a workaround? Looping one more time
> wouldn't change the situation. A dirty workaround I can think of is to
> register a snooping recv() callback and keep looping until recv() hasn't
> received anything during a loop.
>

After looking at the API, I think I have found a solution.

libssh2_channel_window_read_ex() can check if there is data waiting on a
channel, without reading from the socket.

So we would have to run a libssh2_channel_window_read_ex() loop after
each libssh2_channel_read_ex() loop, and repeat both loops until
libssh2_channel_window_read_ex() returns zero for all channels.

-- 
Best Regards,
Tom Weber
Cryptzone Group AB
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-03-12