c++ - OpenSSL connection fails with non-blocking socket -
i have openssl server has echo functionality described here , client described here. made minor changes server (e.g. changing certifiacte , private key paths, adding more debug outputs,...) , in client removed "bio* out" , printed bio_read result console instead. both client , server use tlsv1_1_client_method , tlsv1_1_server_method respectively.
the codes work fine together, if add "bio_set_nbio(web, 1);" client before bio_do_connect, connection doesn't work anymore. bio_do_connect returns -1. can handshake problem , if so, how can handshake non-blocking sockets?
this error first occurred in larger project of mine. used example codes verify it. problem is, need non-blocking sockets, because calling bio_read different thread , can't join thread if it's stuck trying read.
i tried set socket non-blocking using fd_set , select, throws wsaenotsock error (10038). did following:
header:
bio* _bio; ssl* _ssl; fd_set _fdset; socket _socket; timeval t;
on connecting:
_bio = bio_new_ssl_connect(_ctx); bio_get_ssl(_bio, &_ssl); ssl_set_mode(_ssl, ssl_mode_auto_retry); bio_set_conn_hostname(_bio, _address); // _address "hostname:port" int connectresult = bio_do_connect(_bio); // ... error handling connect, certificate verification bio_get_fd(_bio, _socket); fd_zero(&_fdset); fd_set(_socket, &_fdset); t.tv_sec = 2; t.tv_usec = 0;
in thread polls socket:
int selectresult = select(0, &fdset, null, null, &t); // <-- throws wsaenotsock if (selectresult > 0) x = bio_read(_bio, &buf, 1);
is select doable if have bio socket?
the client on windows 7 64 bit, server runs on ubuntu 64 bit on vm on same host windows 7.
Comments
Post a Comment