diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-02-01 16:40:28 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-02-01 16:40:28 +0000 |
commit | de5b3ed315e208cd500ec561bb2837a85cfcebb1 (patch) | |
tree | 1ca2b120fde81a15cfe377aa775518da214e7816 /cpp/src | |
parent | Fixed bug #1730 (diff) | |
download | ice-de5b3ed315e208cd500ec561bb2837a85cfcebb1.tar.bz2 ice-de5b3ed315e208cd500ec561bb2837a85cfcebb1.tar.xz ice-de5b3ed315e208cd500ec561bb2837a85cfcebb1.zip |
Expanded tabs into spaces
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceSSL/TransceiverI.cpp | 558 |
1 files changed, 279 insertions, 279 deletions
diff --git a/cpp/src/IceSSL/TransceiverI.cpp b/cpp/src/IceSSL/TransceiverI.cpp index eaf89fafef6..aab359a99e1 100644 --- a/cpp/src/IceSSL/TransceiverI.cpp +++ b/cpp/src/IceSSL/TransceiverI.cpp @@ -35,8 +35,8 @@ IceSSL::TransceiverI::close() { if(_instance->networkTraceLevel() >= 1) { - Trace out(_logger, _instance->networkTraceCategory()); - out << "closing ssl connection\n" << toString(); + Trace out(_logger, _instance->networkTraceCategory()); + out << "closing ssl connection\n" << toString(); } shutdown(); @@ -52,8 +52,8 @@ IceSSL::TransceiverI::shutdownWrite() { if(_instance->networkTraceLevel() >= 2) { - Trace out(_logger, _instance->networkTraceCategory()); - out << "shutting down ssl connection for writing\n" << toString(); + Trace out(_logger, _instance->networkTraceCategory()); + out << "shutting down ssl connection for writing\n" << toString(); } shutdown(); @@ -67,8 +67,8 @@ IceSSL::TransceiverI::shutdownReadWrite() { if(_instance->networkTraceLevel() >= 2) { - Trace out(_logger, _instance->networkTraceCategory()); - out << "shutting down ssl connection for reading and writing\n" << toString(); + Trace out(_logger, _instance->networkTraceCategory()); + out << "shutting down ssl connection for reading and writing\n" << toString(); } shutdown(); @@ -89,125 +89,125 @@ IceSSL::TransceiverI::write(IceInternal::Buffer& buf, int timeout) // if(_isPeerLocal && packetSize > 64 * 1024) { - packetSize = 64 * 1024; + packetSize = 64 * 1024; } #endif while(buf.i != buf.b.end()) { - ERR_clear_error(); // Clear any spurious errors. - assert(_fd != INVALID_SOCKET); - int ret = SSL_write(_ssl, reinterpret_cast<const void*>(&*buf.i), packetSize); - - if(ret <= 0) - { - switch(SSL_get_error(_ssl, ret)) - { - case SSL_ERROR_NONE: - assert(false); - break; - case SSL_ERROR_ZERO_RETURN: - { - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = IceInternal::getSocketErrno(); - throw ex; - } - case SSL_ERROR_WANT_READ: - { - if(!selectRead(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - continue; - } - case SSL_ERROR_WANT_WRITE: - { - if(!selectWrite(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - continue; - } - case SSL_ERROR_SYSCALL: - { - if(ret == -1) - { - if(IceInternal::interrupted()) - { - continue; - } - - if(IceInternal::noBuffers() && packetSize > 1024) - { - packetSize /= 2; - continue; - } - - if(IceInternal::wouldBlock()) - { - if(SSL_want_read(_ssl)) - { - if(!selectRead(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - } - else if(SSL_want_write(_ssl)) - { - if(!selectWrite(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - } - - continue; - } - - if(IceInternal::connectionLost()) - { - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = IceInternal::getSocketErrno(); - throw ex; - } - } - - if(ret == 0) - { - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = 0; - throw ex; - } - - SocketException ex(__FILE__, __LINE__); - ex.error = IceInternal::getSocketErrno(); - throw ex; - } - case SSL_ERROR_SSL: - { - ProtocolException ex(__FILE__, __LINE__); - ex.reason = "SSL protocol error during write:\n" + _instance->sslErrors(); - throw ex; - } - } - } - - if(_instance->networkTraceLevel() >= 3) - { - Trace out(_logger, _instance->networkTraceCategory()); - out << "sent " << ret << " of " << packetSize << " bytes via ssl\n" << toString(); - } - - if(_stats) - { - _stats->bytesSent(type(), static_cast<Int>(ret)); - } - - buf.i += ret; - - if(packetSize > buf.b.end() - buf.i) - { - packetSize = static_cast<int>(buf.b.end() - buf.i); - } + ERR_clear_error(); // Clear any spurious errors. + assert(_fd != INVALID_SOCKET); + int ret = SSL_write(_ssl, reinterpret_cast<const void*>(&*buf.i), packetSize); + + if(ret <= 0) + { + switch(SSL_get_error(_ssl, ret)) + { + case SSL_ERROR_NONE: + assert(false); + break; + case SSL_ERROR_ZERO_RETURN: + { + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = IceInternal::getSocketErrno(); + throw ex; + } + case SSL_ERROR_WANT_READ: + { + if(!selectRead(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + continue; + } + case SSL_ERROR_WANT_WRITE: + { + if(!selectWrite(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + continue; + } + case SSL_ERROR_SYSCALL: + { + if(ret == -1) + { + if(IceInternal::interrupted()) + { + continue; + } + + if(IceInternal::noBuffers() && packetSize > 1024) + { + packetSize /= 2; + continue; + } + + if(IceInternal::wouldBlock()) + { + if(SSL_want_read(_ssl)) + { + if(!selectRead(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + } + else if(SSL_want_write(_ssl)) + { + if(!selectWrite(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + } + + continue; + } + + if(IceInternal::connectionLost()) + { + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = IceInternal::getSocketErrno(); + throw ex; + } + } + + if(ret == 0) + { + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = 0; + throw ex; + } + + SocketException ex(__FILE__, __LINE__); + ex.error = IceInternal::getSocketErrno(); + throw ex; + } + case SSL_ERROR_SSL: + { + ProtocolException ex(__FILE__, __LINE__); + ex.reason = "SSL protocol error during write:\n" + _instance->sslErrors(); + throw ex; + } + } + } + + if(_instance->networkTraceLevel() >= 3) + { + Trace out(_logger, _instance->networkTraceCategory()); + out << "sent " << ret << " of " << packetSize << " bytes via ssl\n" << toString(); + } + + if(_stats) + { + _stats->bytesSent(type(), static_cast<Int>(ret)); + } + + buf.i += ret; + + if(packetSize > buf.b.end() - buf.i) + { + packetSize = static_cast<int>(buf.b.end() - buf.i); + } } } @@ -219,162 +219,162 @@ IceSSL::TransceiverI::read(IceInternal::Buffer& buf, int timeout) while(buf.i != buf.b.end()) { - ERR_clear_error(); // Clear any spurious errors. - assert(_fd != INVALID_SOCKET); - int ret = SSL_read(_ssl, reinterpret_cast<void*>(&*buf.i), packetSize); - - if(ret <= 0) - { - switch(SSL_get_error(_ssl, ret)) - { - case SSL_ERROR_NONE: - assert(false); - break; - case SSL_ERROR_ZERO_RETURN: - { - // - // If the connection is lost when reading data, we shut - // down the write end of the socket. This helps to unblock - // threads that are stuck in send() or select() while - // sending data. Note: I don't really understand why - // send() or select() sometimes don't detect a connection - // loss. Therefore this helper to make them detect it. - // - //assert(_fd != INVALID_SOCKET); - //shutdownSocketReadWrite(_fd); - - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = 0; - throw ex; - } - case SSL_ERROR_WANT_READ: - { - if(!selectRead(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - continue; - } - case SSL_ERROR_WANT_WRITE: - { - if(!selectWrite(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - continue; - } - case SSL_ERROR_SYSCALL: - { - if(ret == -1) - { - if(IceInternal::interrupted()) - { - continue; - } - - if(IceInternal::noBuffers() && packetSize > 1024) - { - packetSize /= 2; - continue; - } - - if(IceInternal::wouldBlock()) - { - if(SSL_want_read(_ssl)) - { - if(!selectRead(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - } - else if(SSL_want_write(_ssl)) - { - if(!selectWrite(_fd, timeout)) - { - throw TimeoutException(__FILE__, __LINE__); - } - } - - continue; - } - - if(IceInternal::connectionLost()) - { - // - // See the commment above about shutting down the - // socket if the connection is lost while reading - // data. - // - //assert(_fd != INVALID_SOCKET); - //shutdownSocketReadWrite(_fd); - - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = IceInternal::getSocketErrno(); - throw ex; - } - } - - if(ret == 0) - { - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = 0; - throw ex; - } - - SocketException ex(__FILE__, __LINE__); - ex.error = IceInternal::getSocketErrno(); - throw ex; - } - case SSL_ERROR_SSL: - { - // - // Forcefully closing a connection can result in SSL_read reporting - // "decryption failed or bad record mac". We trap that error and - // treat it as the loss of a connection. - // - // NOTE: We have to compare the reason string instead - // of the error codes because the error code values - // changed between OpenSSL 0.9.7i and 0.9.7j and - // between OpenSSL 0.9.8a and 0.9.8b... - // - //unsigned long e = ERR_peek_error(); - //if(ERR_GET_LIB(e) == ERR_LIB_SSL && ERR_GET_REASON(e) == SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC) - // - unsigned long e = ERR_peek_error(); - if(ERR_GET_LIB(e) == ERR_LIB_SSL && - strcmp(ERR_reason_error_string(e), "decryption failed or bad record mac") == 0) - { - ConnectionLostException ex(__FILE__, __LINE__); - ex.error = 0; - throw ex; - } - else - { - ProtocolException ex(__FILE__, __LINE__); - ex.reason = "SSL protocol error during read:\n" + _instance->sslErrors(); - throw ex; - } - } - } - } - - if(_instance->networkTraceLevel() >= 3) - { - Trace out(_logger, _instance->networkTraceCategory()); - out << "received " << ret << " of " << packetSize << " bytes via ssl\n" << toString(); - } - - if(_stats) - { - _stats->bytesReceived(type(), static_cast<Int>(ret)); - } - - buf.i += ret; - - if(packetSize > buf.b.end() - buf.i) - { - packetSize = static_cast<int>(buf.b.end() - buf.i); - } + ERR_clear_error(); // Clear any spurious errors. + assert(_fd != INVALID_SOCKET); + int ret = SSL_read(_ssl, reinterpret_cast<void*>(&*buf.i), packetSize); + + if(ret <= 0) + { + switch(SSL_get_error(_ssl, ret)) + { + case SSL_ERROR_NONE: + assert(false); + break; + case SSL_ERROR_ZERO_RETURN: + { + // + // If the connection is lost when reading data, we shut + // down the write end of the socket. This helps to unblock + // threads that are stuck in send() or select() while + // sending data. Note: I don't really understand why + // send() or select() sometimes don't detect a connection + // loss. Therefore this helper to make them detect it. + // + //assert(_fd != INVALID_SOCKET); + //shutdownSocketReadWrite(_fd); + + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = 0; + throw ex; + } + case SSL_ERROR_WANT_READ: + { + if(!selectRead(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + continue; + } + case SSL_ERROR_WANT_WRITE: + { + if(!selectWrite(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + continue; + } + case SSL_ERROR_SYSCALL: + { + if(ret == -1) + { + if(IceInternal::interrupted()) + { + continue; + } + + if(IceInternal::noBuffers() && packetSize > 1024) + { + packetSize /= 2; + continue; + } + + if(IceInternal::wouldBlock()) + { + if(SSL_want_read(_ssl)) + { + if(!selectRead(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + } + else if(SSL_want_write(_ssl)) + { + if(!selectWrite(_fd, timeout)) + { + throw TimeoutException(__FILE__, __LINE__); + } + } + + continue; + } + + if(IceInternal::connectionLost()) + { + // + // See the commment above about shutting down the + // socket if the connection is lost while reading + // data. + // + //assert(_fd != INVALID_SOCKET); + //shutdownSocketReadWrite(_fd); + + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = IceInternal::getSocketErrno(); + throw ex; + } + } + + if(ret == 0) + { + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = 0; + throw ex; + } + + SocketException ex(__FILE__, __LINE__); + ex.error = IceInternal::getSocketErrno(); + throw ex; + } + case SSL_ERROR_SSL: + { + // + // Forcefully closing a connection can result in SSL_read reporting + // "decryption failed or bad record mac". We trap that error and + // treat it as the loss of a connection. + // + // NOTE: We have to compare the reason string instead + // of the error codes because the error code values + // changed between OpenSSL 0.9.7i and 0.9.7j and + // between OpenSSL 0.9.8a and 0.9.8b... + // + //unsigned long e = ERR_peek_error(); + //if(ERR_GET_LIB(e) == ERR_LIB_SSL && ERR_GET_REASON(e) == SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC) + // + unsigned long e = ERR_peek_error(); + if(ERR_GET_LIB(e) == ERR_LIB_SSL && + strcmp(ERR_reason_error_string(e), "decryption failed or bad record mac") == 0) + { + ConnectionLostException ex(__FILE__, __LINE__); + ex.error = 0; + throw ex; + } + else + { + ProtocolException ex(__FILE__, __LINE__); + ex.reason = "SSL protocol error during read:\n" + _instance->sslErrors(); + throw ex; + } + } + } + } + + if(_instance->networkTraceLevel() >= 3) + { + Trace out(_logger, _instance->networkTraceCategory()); + out << "received " << ret << " of " << packetSize << " bytes via ssl\n" << toString(); + } + + if(_stats) + { + _stats->bytesReceived(type(), static_cast<Int>(ret)); + } + + buf.i += ret; + + if(packetSize > buf.b.end() - buf.i) + { + packetSize = static_cast<int>(buf.b.end() - buf.i); + } } } @@ -523,7 +523,7 @@ IceSSL::TransceiverI::checkSendSize(const IceInternal::Buffer& buf, size_t messa { if(buf.b.size() > messageSizeMax) { - throw MemoryLimitException(__FILE__, __LINE__); + throw MemoryLimitException(__FILE__, __LINE__); } } @@ -538,7 +538,7 @@ IceSSL::TransceiverI::getConnectionInfo() const } IceSSL::TransceiverI::TransceiverI(const InstancePtr& instance, SSL* ssl, SOCKET fd, - bool incoming, const string& adapterName) : + bool incoming, const string& adapterName) : _instance(instance), _logger(instance->communicator()->getLogger()), _stats(instance->communicator()->getStats()), @@ -568,6 +568,6 @@ IceSSL::TransceiverI::shutdown() // if(err == 0) { - SSL_shutdown(_ssl); + SSL_shutdown(_ssl); } } |