Subject: Re: [libssh2] Blocking read returns PACKET_EAGAIN if not enough data is available?

Re: [libssh2] Blocking read returns PACKET_EAGAIN if not enough data is available?

From: Eberhard Mattes <em-libssh2_at_online.ms>
Date: Tue, 08 May 2007 17:04:00 +0200

Here's my patch. What do you think?

Eberhard

--- transport.c.orig 2007-04-18 15:19:26.000000000 +0200
+++ transport.c 2007-05-08 15:48:10.000000000 +0200
@@ -251,6 +251,7 @@
         int numdecrypt;
         unsigned char block[MAX_BLOCKSIZE];
         int blocksize;
+ int minimum;
         int encrypted = 1;
 
         do {
@@ -268,6 +269,7 @@
                                           here to make the checks below work
                                           fine still */
                 }
+ minimum = p->total_num ? p->total_num - p->data_num : blocksize;
 
                 /* read/use a whole big chunk into a temporary area stored in
                    the LIBSSH2_SESSION struct. We will decrypt data from that
@@ -282,9 +284,9 @@
                 /* if remainbuf turns negative we have a bad internal error */
                 assert(remainbuf >= 0);
 
- if(remainbuf < blocksize) {
- /* If we have less than a blocksize left, it is too
- little data to deal with, read more */
+ while(remainbuf < minimum) {
+ /* While there is too little data to deal with, read
+ more */
                         ssize_t nread;
 
                         /* move any remainder to the start of the buffer so
@@ -326,11 +328,6 @@
                 /* how much data to deal with from the buffer */
                 numbytes = remainbuf;
 
- if(numbytes < blocksize) {
- /* we can't act on anything less than blocksize */
- return PACKET_EAGAIN;
- }
-
                 if(!p->total_num) {
                         /* No payload package area allocated yet. To know the
                            size of this payload, we need to decrypt the first
@@ -400,7 +397,7 @@
 
                         /* init the data_num field to the number of bytes of
                            the package read so far */
- p->data_num = blocksize-5;
+ p->data_num = p->wptr - p->payload;
 
                         /* we already dealt with a blocksize worth of data */
                         numbytes -= blocksize;

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-05-08