Partially revert 3f647bb779

refs #6724
This commit is contained in:
Gunnar Beutner 2014-08-05 08:40:06 +02:00
parent 9d318c359b
commit da41725e5b
2 changed files with 23 additions and 11 deletions

View File

@ -76,6 +76,7 @@ TlsStream::TlsStream(const Socket::Ptr& socket, ConnectionRole role, const share
*/ */
shared_ptr<X509> TlsStream::GetClientCertificate(void) const shared_ptr<X509> TlsStream::GetClientCertificate(void) const
{ {
boost::mutex::scoped_lock lock(m_SSLLock);
return shared_ptr<X509>(SSL_get_certificate(m_SSL.get()), &Utility::NullDeleter); return shared_ptr<X509>(SSL_get_certificate(m_SSL.get()), &Utility::NullDeleter);
} }
@ -86,6 +87,7 @@ shared_ptr<X509> TlsStream::GetClientCertificate(void) const
*/ */
shared_ptr<X509> TlsStream::GetPeerCertificate(void) const shared_ptr<X509> TlsStream::GetPeerCertificate(void) const
{ {
boost::mutex::scoped_lock lock(m_SSLLock);
return shared_ptr<X509>(SSL_get_peer_certificate(m_SSL.get()), X509_free); return shared_ptr<X509>(SSL_get_peer_certificate(m_SSL.get()), X509_free);
} }
@ -94,12 +96,15 @@ void TlsStream::Handshake(void)
for (;;) { for (;;) {
int rc, err; int rc, err;
rc = SSL_do_handshake(m_SSL.get()); {
boost::mutex::scoped_lock lock(m_SSLLock);
rc = SSL_do_handshake(m_SSL.get());
if (rc > 0) if (rc > 0)
break; break;
err = SSL_get_error(m_SSL.get(), rc); err = SSL_get_error(m_SSL.get(), rc);
}
switch (err) { switch (err) {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
@ -137,10 +142,13 @@ size_t TlsStream::Read(void *buffer, size_t count)
while (left > 0) { while (left > 0) {
int rc, err; int rc, err;
rc = SSL_read(m_SSL.get(), ((char *)buffer) + (count - left), left); {
boost::mutex::scoped_lock lock(m_SSLLock);
rc = SSL_read(m_SSL.get(), ((char *)buffer) + (count - left), left);
if (rc <= 0) if (rc <= 0)
err = SSL_get_error(m_SSL.get(), rc); err = SSL_get_error(m_SSL.get(), rc);
}
if (rc <= 0) { if (rc <= 0) {
switch (err) { switch (err) {
@ -181,10 +189,13 @@ void TlsStream::Write(const void *buffer, size_t count)
while (left > 0) { while (left > 0) {
int rc, err; int rc, err;
rc = SSL_write(m_SSL.get(), ((const char *)buffer) + (count - left), left); {
boost::mutex::scoped_lock lock(m_SSLLock);
rc = SSL_write(m_SSL.get(), ((const char *)buffer) + (count - left), left);
if (rc <= 0) if (rc <= 0)
err = SSL_get_error(m_SSL.get(), rc); err = SSL_get_error(m_SSL.get(), rc);
}
if (rc <= 0) { if (rc <= 0) {
switch (err) { switch (err) {
@ -221,7 +232,7 @@ void TlsStream::Write(const void *buffer, size_t count)
*/ */
void TlsStream::Close(void) void TlsStream::Close(void)
{ {
for (;;) { for (int i = 0; i < 5; i++) {
int rc, err; int rc, err;
do { do {

View File

@ -54,6 +54,7 @@ public:
private: private:
shared_ptr<SSL> m_SSL; shared_ptr<SSL> m_SSL;
mutable boost::mutex m_SSLLock;
BIO *m_BIO; BIO *m_BIO;
Socket::Ptr m_Socket; Socket::Ptr m_Socket;