[Gambas-user] Support for IMAP in gb.net.curl

Tony Morehen tmorehen at ...3602...
Thu Sep 28 04:34:57 CEST 2017


Benoit, the Read issue is resolved.  I tested using both the the 
existing code, with the read loop and the original code where it tries 
to read the entire message at once.  Both work for both a TCP connection 
and an openssl connection.

However, the send comand for a TCP connection raises a socket closed 
error.  Not right away, but after several send commands. It seems to be 
a timing issue, the error is not raised when I step through the code.  
The send command is simply:

Public Sub Send(Data As String)

   Print #$hStream, Data

End

There is no error at all using an ssl connection.


On 2017-09-26 08:59 PM, Benoît Minisini via Gambas-user wrote:
> Hi, Tony.
>
> I have just pushed the 'rework-stream-interface' branch to the gitlab 
> repository.
>
> I have reworked the internal interpreter stream interface, so that 
> incomplete reads are retried automatically until all the data is read 
> or an error occurs, whatever the underlying stream.
>
> Can you try it and tell me if it fixes the incomplete read on TCP 
> sockets?
>
> Regards,
>
> Le 24/09/2017 à 04:07, Tony Morehen a écrit :
>> I came across an interesting issue when working on Imap's Fetch 
>> command.  Fetch is used to down load messages.  The response to a 
>> Fetch has 4 parts:
>> 1) a single line providing the size of the download, say, 69000 bytes.
>> 2) the mime-encoded download (a string 69000 bytes long)
>> 3) one line whose only contents is ")"
>> 4) one line status line.
>>
>> So my code does:
>> Readline
>> response = Read #stream, iSize    'iSize=69000
>> Readline
>> Readline
>>
>> Using a TCP socket,  the Read # line has no error but the download is 
>> incomplete, say only 50000 bytes.  The remaining 19000 byes is read 
>> by the next Readline.  However, the response variable is the correct 
>> 69000 bytes in length, with the last 19000 bytes zero-filled.  Its 
>> like the Read # timed out but the timeout is set to 10000 and 10 
>> seconds had not elapsed. Socket.blocking was set to True.
>>
>> Using an openssl process, the Read # line raises an error: Error 9, 
>> Bad file descriptor.
>>
>> I have a workaround:  Read # is replaced with
>>
>>    Dim result as new String[]
>>
>>    Bytesread=0
>>    Do While BytesRead < iSize
>>      Response = Read #$hStream,  IIf(iSize - BytesRead > 4096, 4096, 
>> iSize - BytesRead)
>>      result.Add(Response)
>>      bytesread += 4096
>>    Loop
>>    Response = result.Join("")
>>
>> Now both TCP and openssl work, no zero-fill no errors.
>>
>> Any ideas? Other fixes?
>>
>






More information about the User mailing list