> 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 */

This says, "either all my data will be sent or none of it will". How can
that possibly be done in a non-blocking way? What is OpenSSL supposed to do
if the underlying socket accepts a partial write?

> 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

Right.

> 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?

You are correct. If you successfully send the first 50 bytes of the 100
bytes you wanted to send, you now only need to send the 50 remaining bytes.

Note that if you have partial writes disabled, there's only one reason to
call SSL_write a second time after a partial return (since the underlying
write already tried to avoid a partial write and that must have failed to
send any more data). The reason wouled be to determine if the problem was a
fatal connection problem, a 'want read' indication, or a 'want write'
indication. Otherwise, it's hard to know when to try writing again.

DS


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

Reply via email to