code: Fix openssl BIO connect err checking.

Some BIO functions returns -1 for errors, others return -1 or 0 for error!

We need to check for both reads and writes since for select marks a fd as both
readable and writable in case of an error. With the BSD sockets API, we would
use getsockopt() for determining if an error occured. With BIO, we use the
retval of BIO_do_connect.