forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateIoCompletionPort.cs
More file actions
38 lines (31 loc) · 1.15 KB
/
Copy pathCreateIoCompletionPort.cs
File metadata and controls
38 lines (31 loc) · 1.15 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#nullable enable
using System.Runtime.InteropServices;
internal static partial class Interop
{
internal static unsafe partial class Windows
{
internal sealed class SafeIoCompletionPort : SafeHandle
{
public SafeIoCompletionPort() : base(invalidHandleValue: nint.Zero, ownsHandle: true) { }
public override bool IsInvalid => handle == nint.Zero;
protected override bool ReleaseHandle()
=> Windows.CloseHandle(handle);
}
[LibraryImport("kernel32.dll", SetLastError = true)]
private static partial SafeIoCompletionPort CreateIoCompletionPort(
nint FileHandle,
nint ExistingCompletionPort,
nint CompletionKey,
int NumberOfConcurrentThreads);
internal static SafeIoCompletionPort CreateIoCompletionPort()
{
return CreateIoCompletionPort(
FileHandle: -1,
ExistingCompletionPort: nint.Zero,
CompletionKey: nint.Zero,
NumberOfConcurrentThreads: 1);
}
}
}