This is a discussion on Re: non-blocking BIO_do_connect problems with select - Openssl ; On Thu, Jan 17, 2008, Yolanda Liu (liuyu) wrote: > Hi, all: > > Wondering if anybody has done something related this and give me some > suggestions. > > I am using OpenSsl library to do connection to a ...
On Thu, Jan 17, 2008, Yolanda Liu (liuyu) wrote:
> Hi, all:
> Wondering if anybody has done something related this and give me some
> I am using OpenSsl library to do connection to a port. OpenSSL doesn't
> provide a configurable timeout for BIO_do_connect. It is relying on the
> underlying OS connection. If the port is unreachable, it will take about
> 2.5 mins to timeout, just like what telnet does to a port. Looks like
> the only way to do a non-blocking IO is to use select or poll. I made
> read/write work after the connection is established.
> Now the problem is before the connection is established. Select is based
> on the file descriptor. Looks like I can't get the file descriptor
> before the connect. FD_SET(BIO_get_fd(conn, &c), &rfds) BIO_get_fd
> returns null. what did I do wrong?
Call BIO_set_nbio() once after creating the BIO with BIO_new_connect().
Call BIO_do_connect() first and check its return value. If it indicates a
retry is needed (see manual pages) then get the FD and select on it if
necessary. If select returns before the timeout then loop round and call
BIO_do_connect() again repeating until it times out or BIO_do_connect()
indicates you shouldn't retry any more (success or faiure of connection).
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
OpenSSL Project http://www.openssl.org
User Support Mailing List firstname.lastname@example.org
Automated List Manager email@example.com