On Saturday 31 March 2007 00:26, David Schwartz wrote:
> > I see, so if I disable PARTIAL_WRITES, will that mean that it will return
> > values as I wrote up there?
>
> PARTIAL_WRITES has no effect on the meaning of the return value. It just
> controls whether or not the internal write logic tries to continue writing
> if the underlying write partially completes. With or without PARTIAL_WRITES
> enabled, if the socket buffer and internal SSL buffers get full after some
> of the data has been accepted, you will get a partial write if the socket
> is non-blocking.
>
> > Otherwise I fail to see the difference between allowin partial
> > writes and not.
>
> The difference for a non-blocking socket, is that with PARTIAL_WRITES
> disabled, the underlying internal write operation will be retried until it
> is unable to accept any bytes at all. With PARTIAL_WRITES enabled, only one
> call to the underlying internal write operation will be made.
>
> > Furthermore, that would mean that I should actually call
> > SSL_write with new
> > arguments on the same packet.
>
> I don't know what you mean by "the same packet". Packets are below the TCP
> level and have no meaning at or above the TCP level.

Sorry, was a bit cryptic there I guess.
With packet I meant, chunk of application data that I want to send.
like
unsigned char *buffer  = "Hello";  /* this is what I call packet */

> > SSL_write(ssl,  buffer + written, len - written);
> >
> > or am I being retarded here ?
>
> If a previous SSL_write has successfully queued some bytes for sending, you
> don't want to send those same bytes again. In any non-blocking socket
> application, you have to handle partial writes (a form of *success*) by
> saving the rest of the data for when your next write attempt.

It's just this I'm having a hard trouble to grasp.
Normally with say 'write' I would do

// pseudo code
while(written < len)
   written += write(fd, my_packet + written, len - written);

But because SSL_write handles an internal queue and calls for sending the same 
argument all the time I thought I would do:

while( SSL_write(ssl, my_packet, len) <= 0 )  
/* I assume I get SSL_WANTS_WRITE here */

Meaning, SSL_write only returns 0 - get_error returns SSL_WANTS_WRITE
But with partial writes (or perhaps even otherwise) I will have to send that I 
could not send before

while( (ret=SSL_write(ssl, my_packet + written, len - written)) <= 0 || 
written < len) written+=ret;
/* something like that */

Meaning, SSL_write will return 0 for SSL_WANTS_WRITE if something failed and 
it wants to get called again, with the SAME value   (my_packet + written, 
len-written).
And return for instance the number 5 if 5 bytes has been written.
Therefore, thereafter I must call (my_packet + written(5), len-written(5))
and continue to do so as long as I get SSL_WANTS_WRITE
Am I wrong with this?

I have also seen in the write function that a value called ret (return value 
on success?) is stored with the value of the initial 'len'.
Which made me think that under some circuimstances the SSL_write
would actually return 

SSL_write(buffer, len)  - 0 - SSL_WANTS_WRITE
SSL_write(buffer,len) - 0 - SSL_WANTS_WRITE
SSL_write(buffer,len) - len - everything done

Thanks for trying to explain this to me.
I'm just sorry I couldn't get it the first time :/

/Tommy Wallberg
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to