-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressTable.cs
60 lines (48 loc) · 1.47 KB
/
AddressTable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Extensions.Logging;
namespace Smdn.Net.AddressTables;
/// <summary>
/// Provides a mechanism for referencing address tables such as ARP table.
/// </summary>
public abstract partial class AddressTable : IAddressTable {
private bool isDisposed;
protected ILogger? Logger { get; }
protected AddressTable(
ILogger? logger = null
)
{
Logger = logger;
}
/// <inheritdoc cref="IDisposable.Dispose" />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
isDisposed = true;
}
protected void ThrowIfDisposed()
{
if (isDisposed)
throw new ObjectDisposedException(GetType().FullName);
}
/// <summary>
/// Refers to and enumerates the list of entries from the address table.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken" /> to monitor for cancellation requests.</param>
public IAsyncEnumerable<AddressTableEntry> EnumerateEntriesAsync(
CancellationToken cancellationToken = default
)
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
return EnumerateEntriesAsyncCore(cancellationToken);
}
protected abstract IAsyncEnumerable<AddressTableEntry> EnumerateEntriesAsyncCore(CancellationToken cancellationToken);
}