On Tue, Aug 22, 2006 at 03:00:46PM +0200, Marek Marcola wrote:
> You may use select() but with some care.
> Simplest way is to:
>  1) wait on select()
>  2) read hit from SSL descriptor occur
>  3) read incrementally with SSL_read() from that descriptor until
> WANT_READ
>    (or in other words - get all data from SSL read buffer)
>  4) go to select()
  
  So does the following not-really-pseudocode look right (connobjs is
a linked list of connection objects)?

for(cp = connobjs; cp; cp = cp->next)
        cp->want_write = false;

while(!quit) {
  for(cp = connobjs; cp; cp = cp->next) {
        if(cp->want_write || cp->output_buffer) {
                /* either openssl wants to say something, or
                 * we want to send something */
                FD_SET(cp->fd, &writefds);
        } else {
                FD_SET(cp->fd, &readfds);
        }
  }

  select(maxfd + 1, &readfds, &writefds, NULL, &timeout);

  for(cp = connobjs; cp; cp = cp->next) {
        if(cp->want_write || cp->output_buffer) {
                if(FD_ISSET(&cp->fd, &writefds) {
                        if(cp->output_buffer) {
                                byteswr = SSL_write(cp->sslobj,
                                        cp->output_buffer,
                                        cp->output_bufsz);
                                if(byteswr <= 0) {
                                        err = ERR_get_error(cp->sslobj);
                                        if(err == SSL_ERROR_WANT_WRITE)
                                                cp->want_write = true;
                                } else {
                                        
remove_bytes_from_beginning_of_buffer(cp->output_buffer,
                                                        cp->output_bufsz);
                                }
                        }
                }
        }
    }
}

  You'll note I ignore SSL_ERROR_WANT_READ, because I am always
interested in if the server has anything to say, so I will always have
every fd in the readfds set _except_ when the last SSL error was
SSL_ERROR_WANT_WRITE.

  This sound like it's probably a very FAQ.  Once this is sorted out
is there somewhere I should send it to for inclusion?

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

Reply via email to