diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2020-12-08 13:21:32 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-12-08 13:29:30 +0000 |
commit | 7ff3d96a48d703b80f1c774e98228103f52d9c83 (patch) | |
tree | cfbb20eb6d70f2b8ee3a1f5d2d61ffda589ef0c0 | |
parent | wsd: log: overload chrono duration to simplify logging (diff) | |
download | online-private/mmeeks/eagain-simulation.tar.gz online-private/mmeeks/eagain-simulation.zip |
Simulate EAGAIN in debug mode, every seventh operation.
private/mmeeks/eagain-simulation
Hopefully reasonably simple; we perturb the count in the poll to
avoid starving a seventh socket in a poll.
Change-Id: I1a39cc36b9599ffe82186b896c6fd91d792c4127
-rw-r--r-- | net/Socket.cpp | 32 | ||||
-rw-r--r-- | net/Socket.hpp | 15 | ||||
-rw-r--r-- | net/SslSocket.hpp | 13 |
3 files changed, 59 insertions, 1 deletions
diff --git a/net/Socket.cpp b/net/Socket.cpp index 4e14d66810..344c0809e5 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -1,4 +1,3 @@ - /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This Source Code Form is subject to the terms of the Mozilla Public @@ -62,6 +61,32 @@ int Socket::createSocket(Socket::Type type) #endif } +#ifdef ENABLE_DEBUG +static std::atomic<long> socketErrorCount; + +bool StreamSocket::simulateSocketError(bool) +{ + if ((socketErrorCount++ % 7) == 0) + { + errno = EAGAIN; + return true; + } + else + return false; +} + +bool SslStreamSocket::simulateSocketError(bool read) +{ + if ((socketErrorCount++ % 7) == 0) + { + _sslWantsTo = read ? SslWantsTo::Read : SslWantsTo::Write; + return true; + } + else + return false; +} +#endif + // help with initialization order namespace { std::vector<int> &getWakeupsArray() @@ -205,6 +230,11 @@ int SocketPoll::poll(int64_t timeoutMaxMicroS) else assertCorrectThread(); +#ifdef ENABLE_DEBUG + // perturb - to rotate errors among several busy sockets. + socketErrorCount++; +#endif + std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); diff --git a/net/Socket.hpp b/net/Socket.hpp index b8b5cfc2ae..75a0349068 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -1264,6 +1264,11 @@ protected: if (_readType == UseRecvmsgExpectFD) return readFD(buf, len, _incomingFD); +#if ENABLE_DEBUG + if (simulateSocketError(true)) + return -1; +#endif + return ::read(getFD(), buf, len); #else return fakeSocketRead(getFD(), buf, len); @@ -1275,6 +1280,10 @@ protected: { assertCorrectThread(); #if !MOBILEAPP +#if ENABLE_DEBUG + if (simulateSocketError(false)) + return -1; +#endif return ::write(getFD(), buf, len); #else return fakeSocketWrite(getFD(), buf, len); @@ -1296,6 +1305,12 @@ protected: return _socketHandler; } +protected: +#if ENABLE_DEBUG + /// Return true and set errno to simulate an error + virtual bool simulateSocketError(bool read); +#endif + private: /// Client handling the actual data. std::shared_ptr<ProtocolHandlerInterface> _socketHandler; diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp index 79415f3c30..0d42f0c9ac 100644 --- a/net/SslSocket.hpp +++ b/net/SslSocket.hpp @@ -113,6 +113,10 @@ public: { assertCorrectThread(); +#if ENABLE_DEBUG + if (simulateSocketError(true)) + return -1; +#endif return handleSslState(SSL_read(_ssl, buf, len)); } @@ -121,6 +125,11 @@ public: assertCorrectThread(); assert (len > 0); // Never write 0 bytes. + +#if ENABLE_DEBUG + if (simulateSocketError(false)) + return -1; +#endif return handleSslState(SSL_write(_ssl, buf, len)); } @@ -148,6 +157,10 @@ public: } private: +#if ENABLE_DEBUG + /// Return true and set errno to simulate an error + virtual bool simulateSocketError(bool read) override; +#endif /// The possible next I/O operation that SSL want to do. enum class SslWantsTo |