mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-23 23:16:39 +01:00
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:
parent
c8027f0f8b
commit
9f177f7e5a
@ -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.
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user