www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: Problem with random delay in terminal

Problem with random delay in terminal

From: Lars Nordin <Lars.Nordin_at_SDlabs.se>
Date: Tue, 26 Jan 2016 17:01:30 +0100

I'm using libssh2 for a simple terminal emulator. I'm not using
local_echo ie. every key pressed is sent to the server and the reply is
written back on the screen.

The problem is that there is a delay in the respons, ie pressing the
letter 'a' is viewed in groups of 3-5 characters with a delay between
the groups of about 0,5s.

I enabled trace but can't find any trace-message about some delays. If a
record the session in wireshark, I can see the response from the server
and the delay is when sending the next package. 116 bytes is sent and 52
is received, with an ACK without data.

For more testing, a just did a libssh2_write (ie. without any keyboard
read) every 100ms and the delay is still there, every 5th character is
delayed.

I tested the same SSH-server using SecureCRT and there is no delay.
Looking at the data on the network the size of the package is 52 bytes
to and from the server (when just hitting the 'a' key) and without any ACK's

Have I missed any setting? I know local_echo is an option, but if
SecureCRT can, why not libssh2?

/Lars
src: (inserted in the ssh2.c example code)
     // MyTerminal
     {
         int c;
         unsigned char buf[256];
          u_long flags = 1;

         ioctlsocket(sock, FIONBIO, &flags);
         libssh2_session_set_blocking(session, 0);
         libssh2_channel_set_blocking(channel, 0);

         libssh2_trace(session, LIBSSH2_TRACE_SOCKET | LIBSSH2_TRACE_TRANS);

         c = 0;
         while (!libssh2_channel_eof(channel)) {
             memset(buf, 0, sizeof(buf));

             if ( c == 'a' ||_kbhit()) {
                 if (c == 'a') Sleep(100); else
                     c = _getch();

                 if (c == 0) c = _getch();
                 buf[0] = c;
                 buf[1] = 0;
                 do {
                     rc = libssh2_channel_write(channel, buf, strlen(buf));
                 } while (rc == LIBSSH2_ERROR_EAGAIN);

                 // libssh2_channel_flush(channel);
             }

             // rc = libssh2_channel_flush(channel);
             rc = libssh2_channel_read(channel, buf, sizeof(buf)-1);
             if (rc > 0) {
                 printf(buf);
             }

         }
     }
     // ------------------------- MyTerminal

Trace:
Fingerprint: 19 19 30 8E AB E9 A3 5D D5 DB E5 32 44 87 73 77 61 72 C9 07
Authentication methods: publickey
     Authentication by public key succeeded.
[libssh2] 0.999234 Socket: Recved 100/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (100 bytes)
0000: 54 C7 A1 74 6D E0 C4 60 92 65 DB FA 16 71 81 FC : T..tm..`.e...q..
0010: 77 39 D6 FB A5 5D 31 28 24 8B F5 52 08 2D 83 86 : w9...]1($..R.-..
0020: 89 D6 9A 38 0B C0 61 E4 F0 F5 7E FC 12 E2 C1 34 : ...8..a...~....4
0030: D9 10 48 3E B4 A5 E3 5E FB DC BC EB BD BA 25 AC : ..H>...^......%.
0040: F8 3C 13 46 DB 72 BA 80 1B 90 79 D4 42 31 2F EE : .<.F.r....y.B1/.
0050: C7 12 61 79 73 52 BB FB 78 AE 64 0C CF 3A CE 43 : ..aysR..x.d..:.C
0060: E8 36 61 28 : .6a(
=> libssh2_transport_read() plain (68 bytes)
0000: 5E 00 00 00 00 00 00 00 3B 4C 61 73 74 20 6C 6F : ^.......;Last lo
0010: 67 69 6E 3A 20 54 75 65 20 4A 61 6E 20 32 36 20 : gin: Tue Jan 26
0020: 31 35 3A 33 38 3A 33 31 20 32 30 31 36 20 66 72 : 15:38:31 2016 fr
0030: 6F 6D 20 31 39 32 2E 31 36 38 2E 32 30 2E 31 39 : om 192.168.20.19
0040: 38 0D 0D 0A : 8...
[libssh2] 0.999234 Transport: Packet type 94 received, length=68
[libssh2] 1.042237 Socket: Recved 68/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (68 bytes)
0000: 17 A3 C1 7A FC 4C 20 FF 14 52 3C 32 16 0C 62 6D : ...z.L ..R<2..bm
0010: 28 CC 97 08 7C 48 FD 71 13 48 7D C5 6A 58 81 37 : (...|H.q.H}.jX.7
0020: CB BC 7B 20 3D EE 48 96 AC C1 7E F1 F5 D0 9D 65 : ..{ =.H...~....e
0030: 4D 71 FB F0 BE 2A 95 C0 45 DA 93 4B B3 37 13 43 : Mq...*..E..K.7.C
0040: DB 57 F3 6B : .W.k
=> libssh2_transport_read() plain (29 bytes)
0000: 5E 00 00 00 00 00 00 00 14 5B 6C 61 6E 6F 40 6C : ^........[lano_at_l
0010: 6F 63 61 6C 68 6F 73 74 20 7E 5D 24 20 : ocalhost ~]$
[libssh2] 1.042237 Transport: Packet type 94 received, length=29
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 01 : ^........
=> libssh2_transport_write plain2 (1 bytes)
0000: 61 : a
[libssh2] 1.676273 Socket: Sent 116/116 bytes at 0031D148
=> libssh2_transport_write send() (116 bytes)
0000: B5 32 EA 56 CE B7 38 89 6E F8 C4 49 75 77 1A 35 : .2.V..8.n..Iuw.5
0010: 71 DF FC 80 2F BC FC 0A 4B A2 EC 91 26 C6 15 BC : q.../...K...&...
0020: 7B B5 05 03 C6 62 A0 10 3A 61 1E 7D 7E 16 18 2D : {....b..:a.}~..-
0030: 0D 4A 76 1A D9 DD F7 39 D0 97 41 63 F0 88 3F 6A : .Jv....9..Ac..?j
0040: EF 28 86 3D C2 92 B3 D1 41 B6 CF EF 1A 92 45 38 : .(.=....A.....E8
0050: 5F 36 B7 E0 BC 5B F7 43 94 59 79 85 CB B4 2F C1 : _6...[.C.Yy.../.
0060: 69 8C 82 A1 E9 42 4F 85 C1 3D 4A 0D 91 BE 86 A2 : i....BO..=J.....
0070: 61 04 17 3E : a..>
[libssh2] 1.677273 Socket: Recved 52/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (52 bytes)
0000: 95 35 93 9E 45 E0 7A BD 1B 15 96 78 3F 55 5F 8C : .5..E.z....x?U_.
0010: FE 06 FA 4D B6 16 67 79 5A 97 C4 73 27 FB A0 F0 : ...M..gyZ..s'...
0020: 5C 40 EE 4E 85 94 18 F0 6B 82 D1 6E 95 C4 61 84 : \@.N....k..n..a.
0030: 86 C7 9D 5E : ...^
=> libssh2_transport_read() plain (10 bytes)
0000: 5E 00 00 00 00 00 00 00 01 61 : ^........a
[libssh2] 1.677273 Transport: Packet type 94 received, length=10
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 01 : ^........
=> libssh2_transport_write plain2 (1 bytes)
0000: 61 : a
[libssh2] 2.333311 Socket: Sent 116/116 bytes at 0031D148
=> libssh2_transport_write send() (116 bytes)
0000: E7 A4 AB 3B 35 CE BD 4B 60 51 07 64 D5 01 5A B8 : ...;5..K`Q.d..Z.
0010: 06 F5 99 C6 1F D0 27 F0 9C 76 26 8C EA 63 B9 26 : ......'..v&..c.&
0020: 29 D3 59 7B 2F 5F 86 20 8C F8 12 7B 26 6B C6 47 : ).Y{/_. ...{&k.G
0030: 7E EB 8E C9 F9 BA 64 B8 44 23 7D D7 8F F7 A8 6C : ~.....d.D#}....l
0040: 6A 37 8D 9E 9E E5 AD 51 86 AE C5 CD B4 2F A6 6D : j7.....Q...../.m
0050: E7 57 93 C3 CB 11 7D FE 86 31 94 F3 F8 53 58 A9 : .W....}..1...SX.
0060: DF DA 71 37 F8 86 B4 45 AE B7 55 4F 75 3E 0A 12 : ..q7...E..UOu>..
0070: 10 C0 DA F5 : ....
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 01 : ^........
=> libssh2_transport_write plain2 (1 bytes)
0000: 61 : a
[libssh2] 2.333311 Socket: Sent 116/116 bytes at 0031D148
=> libssh2_transport_write send() (116 bytes)
0000: 7B E2 6F 07 D2 72 B5 B0 63 F5 87 C8 19 D7 98 44 : {.o..r..c......D
0010: 0F A3 C6 BE 08 E7 76 DC 8D 7C 35 AF 0D 7F A7 D0 : ......v..|5.....
0020: 97 C0 74 39 1E F6 ED 97 5E 73 3C 35 0C E1 3D D6 : ..t9....^s<5..=.
0030: 61 54 99 A7 6C C6 BE F5 5E 16 F6 AB AA BE E7 60 : aT..l...^......`
0040: 79 19 24 EA 82 DF 74 F5 31 B5 18 4F DF 87 6F F4 : y.$...t.1..O..o.
0050: 0C C5 E3 64 2E 01 B4 42 6B D9 35 0E CF 10 E7 EF : ...d...Bk.5.....
0060: 82 72 CC 7C AB 9A 02 1E 83 29 0B C1 C4 53 26 12 : .r.|.....)...S&.
0070: D3 AA CA 26 : ...&
[libssh2] 2.335311 Socket: Recved 52/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (52 bytes)
0000: 3A C4 C7 34 D8 E0 94 AF 04 8E EB B1 1A AC 61 CE : :..4..........a.
0010: FE BD E6 0B 81 6C 0C 0F E4 25 08 40 90 15 7F B1 : .....l...%.@....
0020: 6F 96 9A 4E AA 61 F2 80 D6 1D 3C 04 44 B0 EE 1B : o..N.a....<.D...
0030: 9A D4 C6 ED : ....
=> libssh2_transport_read() plain (10 bytes)
0000: 5E 00 00 00 00 00 00 00 01 61 : ^........a
[libssh2] 2.335311 Transport: Packet type 94 received, length=10
[libssh2] 2.336311 Socket: Recved 52/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (52 bytes)
0000: 3A 72 EA 77 82 81 D7 B4 3D 82 A3 D9 DE 9D B8 59 : :r.w....=......Y
0010: CE 2B FA 21 32 97 B2 6E 85 D0 8B 9E B1 59 D2 66 : .+.!2..n.....Y.f
0020: 5E 81 93 72 7F 73 66 CD C3 79 C0 86 5C 4E 35 F2 : ^..r.sf..y..\N5.
0030: CF 0E 23 33 : ..#3
=> libssh2_transport_read() plain (10 bytes)
0000: 5E 00 00 00 00 00 00 00 01 61 : ^........a
[libssh2] 2.337311 Transport: Packet type 94 received, length=10
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 01 : ^........
=> libssh2_transport_write plain2 (1 bytes)
0000: 61 : a
[libssh2] 2.341311 Socket: Sent 116/116 bytes at 0031D148
=> libssh2_transport_write send() (116 bytes)
0000: EC 3E A7 A9 90 C1 19 49 8E C2 23 E9 58 12 CE B8 : .>.....I..#.X...
0010: BF AE 41 B5 F0 34 CA ED 55 CF 12 44 19 92 3D 65 : ..A..4..U..D..=e
0020: 7E 0E F6 A2 14 1B 3B 1B A6 03 E7 04 DC 6E 3E DB : ~.....;......n>.
0030: D6 3B 7C 60 AE 57 9E EA 88 72 7E 52 0F 1D 4C 9F : .;|`.W...r~R..L.
0040: 9E 34 0F 91 7F F2 B9 8A F8 0D 43 67 2E EF C1 BA : .4........Cg....
0050: F2 14 D3 B8 37 B2 D0 84 7B 71 EA BB CA 92 62 06 : ....7...{q....b.
0060: 1B C6 1B B1 DD 70 94 43 03 C4 40 F9 87 9A BB 05 : .....p.C..@.....
0070: 18 CD DB 8F : ....
[libssh2] 2.342311 Socket: Recved 52/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (52 bytes)
0000: BB BB 07 27 11 38 B0 D9 53 B8 44 64 1F 43 72 2D : ...'.8..S.Dd.Cr-
0010: 2A 1A D5 6D 5F B0 02 AD 4A 9D 49 7F 97 13 5B 6A : *..m_...J.I...[j
0020: A8 76 D5 9E E6 48 D1 46 0F 53 A1 05 1C 97 AD BC : .v...H.F.S......
0030: 2C 0A 97 C6 : ,...
=> libssh2_transport_read() plain (10 bytes)
0000: 5E 00 00 00 00 00 00 00 01 61 : ^........a
[libssh2] 2.343311 Transport: Packet type 94 received, length=10
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 01 : ^........
=> libssh2_transport_write plain2 (1 bytes)
0000: 61 : a
[libssh2] 2.374313 Socket: Sent 116/116 bytes at 0031D148
=> libssh2_transport_write send() (116 bytes)
0000: 36 A2 03 4E C9 8E B6 BD 6A A8 7D F5 BC CE E1 4F : 6..N....j.}....O
0010: 29 78 3E 5B F0 B7 1F 80 FD 74 0F 33 06 85 91 BD : )x>[.....t.3....
0020: 07 8A D3 CB ED E9 39 3D 86 32 42 EF 1F 59 D4 30 : ......9=.2B..Y.0
0030: 48 0A FF 57 2B 9C 80 FB 60 76 98 2C E1 0E 9B FA : H..W+...`v.,....
0040: C3 66 35 CD 68 92 F6 02 95 B9 2E EE 8A 0A 56 AD : .f5.h.........V.
0050: 26 3B 8D C1 D4 47 AE 44 9C 56 1D D6 34 F5 08 CD : &;...G.D.V..4...
0060: 03 A1 BB 4A CA BB CD 30 74 DB 5D 81 E5 0D E1 F5 : ...J...0t.].....
0070: A7 B4 BD 71 : ...q
[libssh2] 2.375313 Socket: Recved 52/16384 bytes to 00319120+0
=> libssh2_transport_read() raw (52 bytes)
0000: CD 79 5C 41 32 B1 DB 6C C4 F8 57 EE BA 2D B1 89 : .y\A2..l..W..-..
0010: 17 A8 B6 C8 21 09 61 D5 DF 21 19 17 2F 1E 03 FE : ....!.a..!../...
0020: 1E FF 37 D1 DD F0 BD C0 2F DA 02 69 4C 2D 2A 38 : ..7...../..iL-*8
0030: 70 AA 3B 19 : p.;.
=> libssh2_transport_read() plain (10 bytes)
0000: 5E 00 00 00 00 00 00 00 01 61 : ^........a
[libssh2] 2.375313 Transport: Packet type 94 received, length=10
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 01 : ^........
=> libssh2_transport_write plain2 (1 bytes)
0000: 61 : a
[libssh2] 2.407315 Socket: Sent 116/116 bytes at 0031D148
=> libssh2_transport_write send() (116 bytes)
0000: ED CB 88 B6 1F 98 FC 95 87 67 4E A2 0C 14 3D DA : .........gN...=.
0010: E0 2C 95 59 98 ED 5D D4 42 E1 01 5B CF B6 26 70 : .,.Y..].B..[..&p
0020: D5 16 62 9A 7B 50 75 DD 4A A0 77 07 74 43 FE 57 : ..b.{Pu.J.w.tC.W
0030: 07 9C FD DF 98 66 DB 1E 8C 04 10 B7 84 16 7E E6 : .....f........~.
0040: 9B BF F5 B6 B3 C3 0B A1 B7 E4 81 BE FE FB 84 0E : ................
0050: 70 6C 1C 79 4A B9 02 B5 B8 7A 69 D9 40 CD D3 F6 : pl.yJ....zi.@...
0060: 85 DA 76 11 77 40 8A 1D 69 4B D2 EA 68 4F 47 FA : ..v.w@..iK..hOG.
0070: 3F 8B 17 FE : ?...

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2016-01-26

the libssh2 team