Hi all,

i'm facing two kind of problems that possibly are connected together in some 
way. These are basically related to a SFTP download using non blocking sockets 
(the file was about 2 Mega). What i noticed is that:

1) If i use a window size of 32768 at a certain point the libssh2_sftp_read 
returns a EAGAIN value forever. The select doesn't return any negative or zero 
values, meaning probably that the library is not reading anymore from the 
socket ... This problem presents itself in a quite random fashion, so sometimes 
the file is downloaded sometimes not.

2) Lowering the download windows size, library seems to work correctly. But i 
tried to do an experiment: while download was in progress i put the openSSH 
server offline (unpluggin the cable) the result was that the library 
libssh2_sftp_read returned a EAGAIN value forever, and the select didn't fail 
at all.

I'm currently working as a client on a SUN Solaris 9 and as servers i tried on 
a linux machine and a HP-UX machine, both shipping openSSH servers.

Please could you comment on those?
I'm sending also my source code which follows very nearly the implementation of 
the example sftp_RW_nonblock

Thanks in advance,
Antonio


------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-modeĀ™ di Wind
http://i-mode.wind.it/

#define MAX_SEGMENT_SIZE 32768

....CUT......

libssh2_session_set_blocking(myssh_session, 0);

 do {

                do {

        char mem[MAX_SEGMENT_SIZE];

        if (tbd < MAX_SEGMENT_SIZE)
                        get_this = tbd;
        else
                        get_this = MAX_SEGMENT_SIZE;

        rc = libssh2_sftp_read(mysftp_handle, mem, get_this);
                        if (rc > 0)
                                {
                                        printf ("Got %d bytes",rc);
                                        fflush (NULL);
                                        tbd = tbd - rc;
                            rwr = fwrite(mem, rc , 1,stream);
                            if (rwr != 1)
                                {
                                                // Local filesystem error - 
return immediately
                                                fclose (stream);
                                                return 
SSHREAD_ERRORWRITINGLOCAL;
                                }

                                }
                        if ( tbd == 0) break;
                } while (rc > 0 );

        if (tbd == 0) break; //end of download

        if (rc != LIBSSH2_ERROR_EAGAIN)
                {
                                                fclose (stream);
                                                switch (rc)
                                                                                
                {
                                                                                
                                case LIBSSH2_ERROR_ALLOC :
                                                                                
                                        retu = SSHREAD_INTERNAL_ALLOC_ERROR;
                                                                                
                                break;

                                                                                
                                case LIBSSH2_ERROR_SOCKET_SEND:
                                                                                
                                        retu = SSHREAD_FAILED_SEND;
                                                                                
                                break;

                                                                                
                                case LIBSSH2_ERROR_SOCKET_TIMEOUT:
                                                                                
                                        retu = SSHREAD_TIMED_OUT;
                                                                                
                                break;

                                                                                
                                case LIBSSH2_ERROR_SFTP_PROTOCOL:
                                                                                
                                        retu = SSHREAD_INVALIDRESPONSE;
                                                                                
                                break;

                                                                                
                                default:
                                                                                
                                        retu = SSHREAD_GENERIC;
                                                                                
                                break;
                                                                                
                }
                                                                                
                break;
                }


                        my_timeout.tv_sec = 10;
        my_timeout.tv_usec = 0;

        FD_ZERO(&myfd);

        FD_SET(my_sock, &myfd);

        /* wait for readable or writeable */
        rc = select(my_sock+1, &myfd, &myfd, NULL, &my_timeout);
        if(rc <= 0)
                {
                fclose (stream);
                retu = SSHREAD_TIMEOUTRESPONSE;
                break;
                }
     } while (1); // End of second do
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel

Reply via email to