net/Socket.hpp | 3 ++- net/SslSocket.hpp | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-)
New commits: commit 026d469734e63e1c26ce2bd4ea7280e0ec0d0939 Author: Michael Meeks <[email protected]> AuthorDate: Tue Dec 10 11:11:20 2019 +0000 Commit: Andras Timar <[email protected]> CommitDate: Mon Jan 6 16:20:52 2020 +0100 tdf#129306 SslSocket: handle EAGAIN properly. Change-Id: I9fb3323b8d071fdc50399a67eb6b0aaeed9342b0 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/84817 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> 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. _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
