Locked busy scope to handle disconnections properly.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using MailKit;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using MailKit;
|
||||
using MailKit.Net.Imap;
|
||||
using Serilog;
|
||||
|
||||
@@ -9,6 +11,8 @@ namespace Wino.Core.Integration;
|
||||
/// </summary>
|
||||
internal class WinoImapClient : ImapClient
|
||||
{
|
||||
private int _busyCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or internally sets whether the QRESYNC extension is enabled.
|
||||
/// It is set by ImapClientPool immidiately after the authentication.
|
||||
@@ -47,6 +51,34 @@ internal class WinoImapClient : ImapClient
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsBusy() => _busyCount > 0;
|
||||
|
||||
public IDisposable GetBusyScope()
|
||||
{
|
||||
Interlocked.Increment(ref _busyCount);
|
||||
return new BusyScope(this);
|
||||
}
|
||||
|
||||
private class BusyScope : IDisposable
|
||||
{
|
||||
private readonly WinoImapClient _client;
|
||||
private bool _disposed;
|
||||
|
||||
public BusyScope(WinoImapClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
Interlocked.Decrement(ref _client._busyCount);
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
Reference in New Issue
Block a user