Commits

Kaya Kupferschmidt committed 8580aa1

Improved OpenSSL error handling

  • Participants
  • Parent commits e764742

Comments (0)

Files changed (2)

source/libs/magnum_net/source/magnum/net/SslSocketStream.cpp

 ----------------------------------------------------------------------------*/
 size_t SslSocketInputStream::read(void *buffer, size_t size) 
 {
-    int ret = SSL_read(m_Socket->m_SslConnection, buffer, (int)size);
-    if (ret == 0) {
-        if (SSL_get_shutdown(m_Socket->m_SslConnection) != 0)
-            return (size_t)EndOfStream;
+    while (true) {
+        int ret = SSL_read(m_Socket->m_SslConnection, buffer, (int)size);
+        if (ret > 0) {
+            return ret;
+        }
+        else {
+            switch (SSL_get_error(m_Socket->m_SslConnection, ret)) {
+                case SSL_ERROR_NONE:
+                    return 0;
+                case SSL_ERROR_WANT_READ:
+                case SSL_ERROR_WANT_WRITE:
+                    continue;
+                //case SSL_ERROR_ZERO_RETURN:
+                default:
+                    return (size_t)EndOfStream;
+            }
+        }
     }
-    else if (ret < 0) {
-        return (size_t)EndOfStream;
-    }
-    return ret;
 }
 
 
 ----------------------------------------------------------------------------*/
 size_t SslSocketOutputStream::write(const void *buffer, size_t size) 
 {
-    int ret = SSL_write(m_Socket->m_SslConnection, buffer, (int)size);
-    return ret;
+    while (true) {
+        int ret = SSL_write(m_Socket->m_SslConnection, buffer, (int)size);
+        if (ret > 0) {
+            return ret;
+        }
+        else {
+            switch (SSL_get_error(m_Socket->m_SslConnection, ret)) {
+                case SSL_ERROR_NONE:
+                    return 0;
+                case SSL_ERROR_WANT_READ:
+                case SSL_ERROR_WANT_WRITE:
+                    continue;
+                //case SSL_ERROR_ZERO_RETURN:
+                default:
+                    throw SocketException();
+            }
+        }
+    }
 }
 
 

source/libs/magnum_net_http/magnum_net_http.files

 source/magnum/net/http/HttpStatus.h
 source/magnum/net/http/HttpStatus.cpp
 unittest/Test_HttpProxy.h
+source/magnum/net/http/HttpResponseParser.h
+source/magnum/net/http/HttpRequestParser.h
+source/magnum/net/http/HttpResponseParser.cpp
+source/magnum/net/http/HttpRequestParser.cpp