Subject: [ libssh2-Bugs-2785173 ] channel_read returns LIBSSH2_ERROR_EAGAIN, no data on socket

[ libssh2-Bugs-2785173 ] channel_read returns LIBSSH2_ERROR_EAGAIN, no data on socket

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Thu, 07 May 2009 19:31:39 +0000

Bugs item #2785173, was opened at 2009-05-01 19:42
Message generated for change (Settings changed) made by bagder
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=2785173&group_id=125852

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: API
Group: None
>Status: Closed
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Daniel Stenberg (bagder)
Summary: channel_read returns LIBSSH2_ERROR_EAGAIN, no data on socket

Initial Comment:
While using libssh2_channel_read_ex(), I found that when the last of the data has been read, the libssh2_channel_read_ex() may return LIBSSH2_ERROR_EAGAIN, but a poll() on the socket times out (eventually). I diagnosed this as packets (channel eof and channel close) in memory, but not processed, so libssh2_channel_eof() remains false. Root caused as a "single shot" call to _libssh2_transport_read() in channel_read(). No call to _libssh2_transport_read() should be made unless the caller continues to call the function until it returns a non-positive value (0 or negative). This will prevent it from leaving unprocessed buffers in memory.

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2009-05-01 21:07

Message:
Ok, now I understand you perfectly and I also see that you're entirely
correct. This actually means we can simplify the channel_read() function
since we can do the transport_read() loop the same way independent of the
state at the top of the function.

See the commit I just did. Please verify this and tell me if it fixes your
problem!

Thanks a lot. If you tell me your real name, I'll give you proper credit
in the changelog etc.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2009-05-01 20:49

Message:
The transport function did not return EAGAIN. It processed a full packet
(fullpacket()), and returned the result (the packet type). Because
_libssh2_transport_read() returns after processing just one packet,
additional packets may be waiting (in memory) to be processed by future
calls to _libssh2_transport_read(). To resolve this I changed
channel_read() in channel.c (around line 1777):

Was:

rc = _libssh2_transport_read(session);

Now:

rc = 1;

while (rc > 0)
    rc = _libssh2_transport_read(session);

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2009-05-01 20:19

Message:
This explanation is not clear to me. If the reason for the
LIBSSH2_ERROR_EAGAIN is a "single shot" call to _libssh2_transport_read()
in channel_read() then didn't that transport function return EAGAIN? If so,
what good would adding a loop do?

Or perhaps put in another way: can you please provide a patch showing what
you suggest?

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=2785173&group_id=125852

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2009-05-07