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 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?
 
Thanks in advance!
 
-Yolanda
 
Here is the code snippet:
 
conn = BIO_new_connect(const_cast<char *>(svrPort.GetString()));
 if(!conn)
 {   return;   }
 
 /* Configure the BIO as a non-blocking one */
   BIO_set_nbio(conn, 1);
   //select on read
    fd_set rfds;
    struct timeval tv;
    FD_ZERO(&rfds);
    int c = 0;
    FD_SET(BIO_get_fd(conn, &c), &rfds);
    //wait up to five seconds
    tv.tv_sec = 5;
    tv.tv_usec = 0;
 
    int retval = select(BIO_get_fd(conn, &c)+1, &rfds, NULL, NULL, &tv);
    if(retval == -1)
    {
        return;
    }
    BIO_do_connect(conn);

Reply via email to