Dr. Stephen Henson
Wed, 10 Mar 2010 14:59:25 -0800
On Tue, Mar 09, 2010, Bin Lu wrote:
> Hi,
>
> I have the following code snippet:
>
> bio = BIO_new_connect(host);
> BIO_set_conn_port(bio, port);
> BIO_set_nbio(bio, 1)
> while (true) {
> status = BIO_do_connect(bio);
> if (status > 0 || !BIO_should_retry(bio)) {
> break;
> }
> sleep(1);
> }
>
> BIO_do_connect() always returns -1 the first time and 1 the 2nd time,
> regardless if the server is reachable or not.
>
> If I use the blocking mode, then it returns 1 on reachable server and hangs
> otherwise, which seems expected.
>
> Is there anything wrong in the above code, why it returns the same value for
> reachable or non-reachable servers?
>
A call cannot immediately determine if a server is reachable. It typically has to wait until it gets a reply from the remote server. That's why you get a retry: the TCP stack is waiting for a response. Only when it gets that response can the connection continue or not as the case may be. Steve. -- Dr Stephen N. Henson. OpenSSL project core developer. Commercial tech support now available see: http://www.openssl.org ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org