feat(SocketReactor): execute permanent completion handlers on when there are I/O handlers and the expired ones whenever they expire

This commit is contained in:
Alex Fabijanic 2021-06-26 15:47:47 +02:00
parent c8027f0f8b
commit 9f177f7e5a
2 changed files with 10 additions and 4 deletions

View File

@ -255,7 +255,7 @@ protected:
/// Can be overridden by subclasses to perform additional
/// periodic tasks. The default implementation does nothing.
int onComplete(bool handleOne = false);
int onComplete(bool handleOne = false, bool expiredOnly = false);
/// Calls completion handler(s) (after poll() completes processing
/// or on runOne() invocation). If handleOne is true, returns
/// after first handler invocation.

View File

@ -70,6 +70,7 @@ SocketReactor::~SocketReactor()
int SocketReactor::poll(int* pHandled)
{
int handled = 0;
int completed = 0;
if (!hasSocketHandlers()) onIdle();
else
{
@ -103,11 +104,16 @@ int SocketReactor::poll(int* pHandled)
if (!readable) onTimeout();
}
if (pHandled) *pHandled = handled;
return onComplete();
if (hasSocketHandlers())
{
if (handled) completed = onComplete();
}
else completed = onComplete(false, true);
return completed;
}
int SocketReactor::onComplete(bool handleOne)
int SocketReactor::onComplete(bool handleOne, bool expiredOnly)
{
std::unique_ptr<CompletionHandler> pCH;
int handled = 0;
@ -121,7 +127,7 @@ int SocketReactor::onComplete(bool handleOne)
// be unlocked before the invocation.
{
SpinScopedLock lock(_completionMutex);
bool alwaysRun = isPermanent(it->second);
bool alwaysRun = isPermanent(it->second) && !expiredOnly;
bool isExpired = !alwaysRun && (Timestamp() > it->second);
if (isExpired)
{