On Tue, Aug 22, 2006 at 12:06:29PM -0400, Steven Young wrote: > 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)?
To answer my own question: No. Here is an amended version. > 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); > } } else { bytesrd = SSL_read(cp->sslobj, cp->input_buffer, cp->input_bufsz); if(bytesrd <= 0) { err = ERR_get_error(cp->sslobj); if(err == SSL_ERROR_WANT_WRITE) cp->want_write = true; } else { do_something_with_buffer(cp); } } } else if(FD_ISSET(cp->fd, &readfds)) { bytesrd = SSL_read(cp->sslobj, cp->input_buffer, cp->input_bufsz); if(bytesrd <= 0) { err = ERR_get_error(cp->sslobj); if(err == SSL_ERROR_WANT_WRITE) cp->want_write = true; } else { do_something_with_buffer(cp); } } > } > } > } There's plenty of redundant code up there but I thought it would be more clear than factoring stuff out. Steve. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]