(openssl + mbedssl) fix #140, can send large files with ws send over ssl / still broken with apple ssl

This commit is contained in:
Benjamin Sergeant 2020-01-12 11:08:44 -08:00
parent a01584ad9d
commit d2c5ab1cc4
4 changed files with 40 additions and 50 deletions

View File

@ -1,6 +1,10 @@
# Changelog # Changelog
All changes to this project will be documented in this file. 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 ## [7.9.3] - 2020-01-10
(apple ssl) model write method after the OpenSSL one for consistency (apple ssl) model write method after the OpenSSL one for consistency

View File

@ -230,30 +230,23 @@ namespace ix
ssize_t SocketMbedTLS::send(char* buf, size_t nbyte) ssize_t SocketMbedTLS::send(char* buf, size_t nbyte)
{ {
ssize_t sent = 0; std::lock_guard<std::mutex> lock(_mutex);
while (nbyte > 0) ssize_t res = mbedtls_ssl_write(&_ssl, (unsigned char*) buf, nbyte);
if (res > 0)
{ {
std::lock_guard<std::mutex> lock(_mutex); return res;
}
ssize_t res = mbedtls_ssl_write(&_ssl, (unsigned char*) buf, nbyte); else if (res == MBEDTLS_ERR_SSL_WANT_READ || res == MBEDTLS_ERR_SSL_WANT_WRITE)
{
if (res > 0) errno = EWOULDBLOCK;
{ return -1;
nbyte -= res; }
sent += res; else
} {
else if (res == MBEDTLS_ERR_SSL_WANT_READ || res == MBEDTLS_ERR_SSL_WANT_WRITE) return -1;
{
errno = EWOULDBLOCK;
return -1;
}
else
{
return -1;
}
} }
return sent;
} }
ssize_t SocketMbedTLS::send(const std::string& buffer) ssize_t SocketMbedTLS::send(const std::string& buffer)

View File

@ -603,37 +603,30 @@ namespace ix
ssize_t SocketOpenSSL::send(char* buf, size_t nbyte) ssize_t SocketOpenSSL::send(char* buf, size_t nbyte)
{ {
ssize_t sent = 0; std::lock_guard<std::mutex> lock(_mutex);
while (nbyte > 0) if (_ssl_connection == nullptr || _ssl_context == nullptr)
{ {
std::lock_guard<std::mutex> lock(_mutex); return 0;
}
if (_ssl_connection == nullptr || _ssl_context == nullptr)
{ ERR_clear_error();
return 0; ssize_t write_result = SSL_write(_ssl_connection, buf, (int) nbyte);
} int reason = SSL_get_error(_ssl_connection, (int) write_result);
ERR_clear_error(); if (reason == SSL_ERROR_NONE)
ssize_t write_result = SSL_write(_ssl_connection, buf + sent, (int) nbyte); {
int reason = SSL_get_error(_ssl_connection, (int) write_result); return write_result;
}
if (reason == SSL_ERROR_NONE) else if (reason == SSL_ERROR_WANT_READ || reason == SSL_ERROR_WANT_WRITE)
{ {
nbyte -= write_result; errno = EWOULDBLOCK;
sent += write_result; return -1;
} }
else if (reason == SSL_ERROR_WANT_READ || reason == SSL_ERROR_WANT_WRITE) else
{ {
errno = EWOULDBLOCK; return -1;
return -1;
}
else
{
return -1;
}
} }
return sent;
} }
ssize_t SocketOpenSSL::send(const std::string& buffer) ssize_t SocketOpenSSL::send(const std::string& buffer)

View File

@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "7.9.3" #define IX_WEBSOCKET_VERSION "7.9.4"