Skip to content

Commit

Permalink
Improve server request handler (#1411)
Browse files Browse the repository at this point in the history
-no need to search request list for every completed request, only if operation deadline is specified
-move timer clean up to timer callback
  • Loading branch information
mregen committed May 25, 2021
1 parent be41459 commit 8a986f4
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions Libraries/Opc.Ua.Server/Server/RequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,6 @@ public void RequestCompleted(OperationContext context)

lock (m_requestsLock)
{
// find the completed request.
bool deadlineExists = false;

foreach (OperationContext request in m_requests.Values)
{
if (request.RequestId == context.RequestId)
{
continue;
}

if (request.OperationDeadline < DateTime.MaxValue)
{
deadlineExists = true;
}
}

// check if the timer can be cancelled.
if (m_requestTimer != null && !deadlineExists)
{
m_requestTimer.Dispose();
m_requestTimer = null;
}

// remove the request.
m_requests.Remove(context.RequestId);
}
Expand Down Expand Up @@ -223,13 +200,27 @@ private void OnTimerExpired(object state)
// flag requests as expired.
lock (m_requestsLock)
{
// find the completed request.
bool deadlineExists = false;

foreach (OperationContext request in m_requests.Values)
{
if (request.OperationDeadline < DateTime.UtcNow)
{
request.SetStatusCode(StatusCodes.BadTimeout);
expiredRequests.Add(request.RequestId);
}
else if (request.OperationDeadline < DateTime.MaxValue)
{
deadlineExists = true;
}
}

// check if the timer can be cancelled.
if (m_requestTimer != null && !deadlineExists)
{
m_requestTimer.Dispose();
m_requestTimer = null;
}
}

Expand Down

0 comments on commit 8a986f4

Please sign in to comment.