Dr S N Henson <[EMAIL PROTECTED]> writes:

> Michael Shanzer wrote:
> > 
> > Is there a select equivlant or is my work around good
> > enough (if SSL_read returns -1 check the return value
> > of SSL_get_error, and if it returns 2, try again...).
> > 
> 
> If you mean retry SSL_read then that will work (eventually...) but it
> will be inefficient. What you should do is to redo the select, using the
> return value of SSL_get_error to decide whether to select on read or
> write. When select indicated data is available then you can retry
> SSL_read, but it could of course return -1 and want more data.
Quite so. I misspoke previously. The correct idiom looks like
this.

      /* Set up the select masks here */

      r=select(width,&readfds,&writefds,0,0);
      if(r==0)
        continue;

      /* Now check if there's data to read */
      if(FD_ISSET(sock,&readfds)){
        do {
          r=SSL_read(ssl,s2c,BUFSIZZ);
          
          switch(SSL_get_error(ssl,r)){
            case SSL_ERROR_NONE:
              /* Do whatever you'd do with the data */
              break;
            case SSL_ERROR_ZERO_RETURN:
              /* End of data */
              if(!shutdown_wait)
                SSL_shutdown(ssl);
              goto end;
              break;
            case SSL_ERROR_WANT_READ:
              break;
            default:
              berr_exit("SSL read problem");
          }
        } while (SSL_pending(ssl));
      }

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

Reply via email to