[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ssh_channel_accept always blocking


Hello,

function ssh_channel_accept() in channels.c always block execution for a
minimal 50 ms:

 for (t = timeout_ms; t >= 0; t -= 100) {
    ssh_handle_packets(session, 50);

It is wrong. Usually if you set timeout to 0, you expecting that
function not blocking execution of process. For example, if you want to
read from ssh channels in loop and accept incoming forward connections:

forever()
{
   /*wait for data 100 msec*/
   ssh_select ( read_chan, out_chan, maxsock+1, &rfds, &tv );

   /*check for incoming connections*/
   ssh_channel chan=ssh_channel_accept_forward(my_ssh_session, 0, &port);
   ......
}

in this case we will always have 50 ms delay, because
ssh_channel_accept() execute poll() with 50 ms timeout. As result we
have pure performance, especially if we transferring video or audio data.

The simple solution is in attached patch.

regards,
Alex
-- 
----------------------------------------------------
Oleksandr Shneyder  | Email: o.shneyder@xxxxxxxxxxxxx
phoca GmbH          | Tel. : 0911 - 14870374 0
Bräuhausgasse 9     | Fax. : 0911 - 14870374 9
D-82205 Gilching    | Mobil: 0163 - 49 64 461

Geschäftsführung:
Dipl.-Inf. Oleksandr Shneyder

Amtsgericht München | http://www.phoca-gmbh.de
HRB 196 658         | http://www.x2go.org
USt-IdNr.: DE281977973
----------------------------------------------------
From 7c8e90c04731b9753f09c736478e0c44a94bfedc Mon Sep 17 00:00:00 2001
From: Oleksandr Shneyder <o.shneyder@xxxxxxxxxxxxx>
Date: Wed, 22 Jan 2014 21:06:13 +0100
Subject: [PATCH] Make function ssh_channel_accept() nonblocking if timeout
 is 0.

---
 src/channels.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/channels.c b/src/channels.c
index 17aed90..ed38956 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -2022,7 +2022,10 @@ static ssh_channel ssh_channel_accept(ssh_session session, int channeltype,
    * 50 ms. So we need to decrement by 100 ms.
    */
   for (t = timeout_ms; t >= 0; t -= 100) {
-    ssh_handle_packets(session, 50);
+    if(!timeout_ms)
+      ssh_handle_packets(session, 0);
+    else
+      ssh_handle_packets(session, 50);
 
     if (session->ssh_message_list) {
       iterator = ssh_list_get_iterator(session->ssh_message_list);
-- 
1.7.10.4

Attachment: signature.asc
Description: OpenPGP digital signature


Archive administrator: postmaster@lists.cynapses.org