diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0304ff84..fa73a0e1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [7.9.4] - 2020-01-12 + +(openssl + mbedssl) fix #140, can send large files with ws send over ssl / still broken with apple ssl + ## [7.9.3] - 2020-01-10 (apple ssl) model write method after the OpenSSL one for consistency diff --git a/ixwebsocket/IXSocketMbedTLS.cpp b/ixwebsocket/IXSocketMbedTLS.cpp index dc6cc5c5..4303943e 100644 --- a/ixwebsocket/IXSocketMbedTLS.cpp +++ b/ixwebsocket/IXSocketMbedTLS.cpp @@ -230,30 +230,23 @@ namespace ix ssize_t SocketMbedTLS::send(char* buf, size_t nbyte) { - ssize_t sent = 0; + std::lock_guard lock(_mutex); - while (nbyte > 0) + ssize_t res = mbedtls_ssl_write(&_ssl, (unsigned char*) buf, nbyte); + + if (res > 0) { - std::lock_guard lock(_mutex); - - ssize_t res = mbedtls_ssl_write(&_ssl, (unsigned char*) buf, nbyte); - - if (res > 0) - { - nbyte -= res; - sent += res; - } - else if (res == MBEDTLS_ERR_SSL_WANT_READ || res == MBEDTLS_ERR_SSL_WANT_WRITE) - { - errno = EWOULDBLOCK; - return -1; - } - else - { - return -1; - } + return res; + } + else if (res == MBEDTLS_ERR_SSL_WANT_READ || res == MBEDTLS_ERR_SSL_WANT_WRITE) + { + errno = EWOULDBLOCK; + return -1; + } + else + { + return -1; } - return sent; } ssize_t SocketMbedTLS::send(const std::string& buffer) diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index 260324a9..5048a289 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -603,37 +603,30 @@ namespace ix ssize_t SocketOpenSSL::send(char* buf, size_t nbyte) { - ssize_t sent = 0; + std::lock_guard lock(_mutex); - while (nbyte > 0) + if (_ssl_connection == nullptr || _ssl_context == nullptr) { - std::lock_guard lock(_mutex); - - if (_ssl_connection == nullptr || _ssl_context == nullptr) - { - return 0; - } - - ERR_clear_error(); - ssize_t write_result = SSL_write(_ssl_connection, buf + sent, (int) nbyte); - int reason = SSL_get_error(_ssl_connection, (int) write_result); - - if (reason == SSL_ERROR_NONE) - { - nbyte -= write_result; - sent += write_result; - } - else if (reason == SSL_ERROR_WANT_READ || reason == SSL_ERROR_WANT_WRITE) - { - errno = EWOULDBLOCK; - return -1; - } - else - { - return -1; - } + return 0; + } + + ERR_clear_error(); + ssize_t write_result = SSL_write(_ssl_connection, buf, (int) nbyte); + int reason = SSL_get_error(_ssl_connection, (int) write_result); + + if (reason == SSL_ERROR_NONE) + { + return write_result; + } + else if (reason == SSL_ERROR_WANT_READ || reason == SSL_ERROR_WANT_WRITE) + { + errno = EWOULDBLOCK; + return -1; + } + else + { + return -1; } - return sent; } ssize_t SocketOpenSSL::send(const std::string& buffer) diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 843736fb..526a44b6 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "7.9.3" +#define IX_WEBSOCKET_VERSION "7.9.4"