summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-12-10 11:11:20 +0000
committerAndras Timar <andras.timar@collabora.com>2020-01-06 16:20:52 +0100
commit026d469734e63e1c26ce2bd4ea7280e0ec0d0939 (patch)
tree805834c645b8675065c1237ba6e0ba86ea221709
parent97c41850e66c3632c73da62d8970750937f97849 (diff)
tdf#129306 SslSocket: handle EAGAIN properly.
Change-Id: I9fb3323b8d071fdc50399a67eb6b0aaeed9342b0 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/84817 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--net/Socket.hpp3
-rw-r--r--net/SslSocket.hpp21
2 files changed, 18 insertions, 6 deletions
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 49cfeab49..e58bbf97e 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -794,7 +794,8 @@ public:
~StreamSocket()
{
- LOG_DBG("StreamSocket dtor #" << getFD());
+ LOG_DBG("StreamSocket dtor #" << getFD() << " with pending "
+ "write: " << _outBuffer.size() << ", read: " << _inBuffer.size());
if (!_closed)
{
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index de16fdf1d..ba9954f56 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -22,28 +22,30 @@ public:
SslStreamSocket(const int fd, bool isClient,
std::shared_ptr<SocketHandlerInterface> responseClient) :
StreamSocket(fd, isClient, std::move(responseClient)),
+ _bio(nullptr),
_ssl(nullptr),
_sslWantsTo(SslWantsTo::Neither),
_doHandshake(true)
{
LOG_DBG("SslStreamSocket ctor #" << fd);
- BIO* bio = BIO_new(BIO_s_socket());
- if (bio == nullptr)
+ _bio = BIO_new(BIO_s_socket());
+ if (_bio == nullptr)
{
throw std::runtime_error("Failed to create SSL BIO.");
}
- BIO_set_fd(bio, fd, BIO_NOCLOSE);
+ BIO_set_fd(_bio, fd, BIO_NOCLOSE);
_ssl = SslContext::newSsl();
if (!_ssl)
{
- BIO_free(bio);
+ BIO_free(_bio);
+ _bio = nullptr;
throw std::runtime_error("Failed to create SSL.");
}
- SSL_set_bio(_ssl, bio, bio);
+ SSL_set_bio(_ssl, _bio, _bio);
if (isClient)
{
@@ -240,6 +242,14 @@ private:
// Fallthrough...
default:
{
+ // Effectively an EAGAIN error at the BIO layer
+ if (BIO_should_retry(_bio))
+ {
+ LOG_TRC("Socket #" << getFD() << " BIO asks for retry - underlying EAGAIN? " <<
+ SSL_get_error(_ssl, rc));
+ return -1; // poll is used to detect real errors.
+ }
+
if (sslError == SSL_ERROR_SSL)
LOG_TRC("Socket #" << getFD() << " SSL error: SSL (" << sslError << ").");
else if (sslError == SSL_ERROR_SYSCALL)
@@ -289,6 +299,7 @@ private:
}
private:
+ BIO* _bio;
SSL* _ssl;
/// During handshake SSL might want to read
/// on write, or write on read.