diff options
author | Benoit Foucher <benoit@zeroc.com> | 2008-01-07 10:30:13 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2008-01-07 10:30:13 +0100 |
commit | d9ce265d9766f0d48c6a6c10491be1f782424a2c (patch) | |
tree | 62df7123b09ccbcc617c6024c4b30e1bec45f16b /cpp/src/IceSSL/ConnectorI.cpp | |
parent | Fixed IceBox/configuration test failure when run with --protocol=ssl (diff) | |
download | ice-d9ce265d9766f0d48c6a6c10491be1f782424a2c.tar.bz2 ice-d9ce265d9766f0d48c6a6c10491be1f782424a2c.tar.xz ice-d9ce265d9766f0d48c6a6c10491be1f782424a2c.zip |
Fixed bug 2304
Diffstat (limited to 'cpp/src/IceSSL/ConnectorI.cpp')
-rw-r--r-- | cpp/src/IceSSL/ConnectorI.cpp | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/cpp/src/IceSSL/ConnectorI.cpp b/cpp/src/IceSSL/ConnectorI.cpp index 31f2c176e15..b66c005dc09 100644 --- a/cpp/src/IceSSL/ConnectorI.cpp +++ b/cpp/src/IceSSL/ConnectorI.cpp @@ -40,36 +40,48 @@ IceSSL::ConnectorI::connect(int timeout) out << "trying to establish ssl connection to " << toString(); } - SOCKET fd = IceInternal::createSocket(false, _addr.ss_family); - IceInternal::setBlock(fd, false); - IceInternal::setTcpBufSize(fd, _instance->communicator()->getProperties(), _logger); - bool connected = IceInternal::doConnect(fd, _addr, timeout); - - // This static_cast is necessary due to 64bit windows. There SOCKET is a non-int type. - BIO* bio = BIO_new_socket(static_cast<int>(fd), BIO_CLOSE); - if(!bio) + try { - IceInternal::closeSocketNoThrow(fd); - SecurityException ex(__FILE__, __LINE__); - ex.reason = "openssl failure"; - throw ex; + SOCKET fd = IceInternal::createSocket(false, _addr.ss_family); + IceInternal::setBlock(fd, false); + IceInternal::setTcpBufSize(fd, _instance->communicator()->getProperties(), _logger); + bool connected = IceInternal::doConnect(fd, _addr, timeout); + + // This static_cast is necessary due to 64bit windows. There SOCKET is a non-int type. + BIO* bio = BIO_new_socket(static_cast<int>(fd), BIO_CLOSE); + if(!bio) + { + IceInternal::closeSocketNoThrow(fd); + SecurityException ex(__FILE__, __LINE__); + ex.reason = "openssl failure"; + throw ex; + } + + SSL* ssl = SSL_new(_instance->context()); + if(!ssl) + { + BIO_free(bio); // Also closes the socket. + SecurityException ex(__FILE__, __LINE__); + ex.reason = "openssl failure"; + throw ex; + } + SSL_set_bio(ssl, bio, bio); + + // + // SSL handshaking is performed in TransceiverI::initialize, since + // connect must not block. + // + return new TransceiverI(_instance, ssl, fd, connected, false); } - - SSL* ssl = SSL_new(_instance->context()); - if(!ssl) + catch(const Ice::LocalException& ex) { - BIO_free(bio); // Also closes the socket. - SecurityException ex(__FILE__, __LINE__); - ex.reason = "openssl failure"; - throw ex; + if(_instance->networkTraceLevel() >= 2) + { + Trace out(_logger, _instance->networkTraceCategory()); + out << "failed to establish ssl connection to " << toString() << "\n" << ex; + } + throw; } - SSL_set_bio(ssl, bio, bio); - - // - // SSL handshaking is performed in TransceiverI::initialize, since - // connect must not block. - // - return new TransceiverI(_instance, ssl, fd, connected, false); } Short |