Just for the record, poll() is also an alternative when implementing a timeout for sockets.
/ Anders On Wed, 20 Apr 2005, Dr. Stephen Henson wrote: > On Wed, Apr 20, 2005, Schneider John wrote: > > > > > I found this snippet for implementing a timeout for sockets, although > > the example had nothing to do with SSL... I put it in some code and it > > seems to work fine, but was wondering if anybody else has tried it or > > can comment on the idea. Thanks! > > > > /////// snippet: > > int err; > > fd_set fds; > > struct timeval tv; > > > > FD_ZERO(&fds); > > FD_SET(socket, &fds); > > tv.tv_sec = 10000; // ten seconds > > tv.tv_usec = 0; > > > > // wait for timeout > > // err = select(socket+1, NULL, &fds, NULL, &tv); // write > > err = select(socket+1, &fds, NULL, NULL, &tv); // read > > if (err == 0) return -2; // timeout > > if (err == -1) return -1; // error > > > > // if we're here, we're OK to do a send > > // SSL_write( ... ) > > SSL_read( ... ) > > > > > > You need to combine that with non-blocking I/O, checking for > SSL_ERROR_WANT_READ etc and processing it in an appropriate manner. > > If you are using blocking I/O what you are doing wont work in all cases. > select() just says there is *some* data available not necessarily enough to > read in a complete record. So SSL_read() could internally read some data which > is only a partial record and then read in more data. For blocking I/O that > second read could end up blocking indefinitely. > > Steve. > -- > Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage > OpenSSL project core developer and freelance consultant. > Funding needed! Details on homepage. > Homepage: http://www.drh-consultancy.demon.co.uk > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager [EMAIL PROTECTED] > ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]