-
Notifications
You must be signed in to change notification settings - Fork 0
/
NtMailslotFile.cs
111 lines (97 loc) · 3.75 KB
/
NtMailslotFile.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace NtApiDotNet
{
/// <summary>
/// Class representing a NT File Mailslot client object
/// </summary>
public class NtMailslotFile : NtFile
{
#region Constructors
internal NtMailslotFile(SafeKernelObjectHandle handle, IoStatus io_status)
: base(handle, io_status)
{
}
#endregion
#region Private Members
private NtResult<FileMailslotQueryInformation> QueryInfo(bool throw_on_error)
{
return Query<FileMailslotQueryInformation>(FileInformationClass.FileMailslotQueryInformation, default, throw_on_error);
}
#endregion
#region Public Methods
/// <summary>
/// Set the mailslot read timeout.
/// </summary>
/// <param name="timeout">The timeout to set.</param>
/// <param name="throw_on_error">True to throw on error.</param>
/// <returns>The NT Status code.</returns>
public NtStatus SetReadTimeout(NtWaitTimeout timeout, bool throw_on_error)
{
LargeInteger read_timeout = timeout?.Timeout ?? new LargeInteger(-1);
FileMailslotSetInformation set_info = new FileMailslotSetInformation()
{
ReadTimeout = read_timeout.ToStruct()
};
return Set(FileInformationClass.FileMailslotSetInformation, set_info, throw_on_error);
}
/// <summary>
/// Peek on the current status of the Mailslot.
/// </summary>
/// <param name="throw_on_error">True to throw on error.</param>
/// <returns>The peek status.</returns>
public NtResult<FileMailslotPeekBuffer> Peek(bool throw_on_error)
{
using (var buffer = new SafeStructureInOutBuffer<FileMailslotPeekBuffer>())
{
return FsControl(NtWellKnownIoControlCodes.FSCTL_MAILSLOT_PEEK, buffer, buffer, throw_on_error).Map(_ => buffer.Result);
}
}
/// <summary>
/// Peek on the current status of the Mailslot.
/// </summary>
/// <returns>The peek status.</returns>
public FileMailslotPeekBuffer Peek()
{
return Peek(true).Result;
}
#endregion
#region Public Properties
/// <summary>
/// Get or set the Read Timeout.
/// </summary>
public NtWaitTimeout ReadTimeout
{
get => QueryInfo(true).Result.ReadTimeout.ToTimeout();
set => SetReadTimeout(value, true);
}
/// <summary>
/// Get maximum message size.
/// </summary>
public int MaximumMessageSize => QueryInfo(true).Result.MaximumMessageSize;
/// <summary>
/// Get mailslot quota.
/// </summary>
public int MailslotQuota => QueryInfo(true).Result.MailslotQuota;
/// <summary>
/// Get next message size.
/// </summary>
public int NextMessageSize => QueryInfo(true).Result.NextMessageSize;
/// <summary>
/// Get messages available.
/// </summary>
public int MessagesAvailable => QueryInfo(true).Result.MessagesAvailable;
#endregion
}
}