Skip to content

Commit 33a8b15

Browse files
authored
Add stub for _winapi.SetNamedPipeHandleState (#1963)
1 parent ff61e59 commit 33a8b15

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/core/IronPython.Modules/_winapi.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using IronPython.Runtime;
1616
using IronPython.Runtime.Operations;
1717

18+
using Microsoft.Win32.SafeHandles;
19+
1820
[assembly: PythonModule("_winapi", typeof(IronPython.Modules.PythonWinApi), PlatformsAttribute.PlatformFamily.Windows)]
1921
namespace IronPython.Modules {
2022
[SupportedOSPlatform("windows")]
@@ -234,6 +236,16 @@ public static int WaitForSingleObject(BigInteger handle, int dwMilliseconds) {
234236
return WaitForSingleObjectPI(new IntPtr((long)handle), dwMilliseconds);
235237
}
236238

239+
public static void SetNamedPipeHandleState(BigInteger named_pipe, object? mode, object? max_collection_count, object? collect_data_timeout) {
240+
if (max_collection_count is not null) throw new NotImplementedException();
241+
if (collect_data_timeout is not null) throw new NotImplementedException();
242+
var pipeHandle = new SafePipeHandle(new IntPtr((long)named_pipe), false);
243+
int m = Converter.ConvertToInt32(mode);
244+
var result = Interop.Kernel32.SetNamedPipeHandleState(pipeHandle, ref m, IntPtr.Zero, IntPtr.Zero);
245+
246+
if (!result) throw PythonNT.GetLastWin32Error();
247+
}
248+
237249
#endregion
238250

239251
#region struct's and enum's
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.Win32.SafeHandles;
5+
6+
using System;
7+
using System.Runtime.InteropServices;
8+
9+
internal static partial class Interop {
10+
internal static partial class Kernel32 {
11+
[DllImport(Libraries.Kernel32, SetLastError = true)]
12+
[return: MarshalAs(UnmanagedType.Bool)]
13+
internal static extern unsafe bool SetNamedPipeHandleState(
14+
SafePipeHandle hNamedPipe,
15+
ref int lpMode,
16+
IntPtr lpMaxCollectionCount,
17+
IntPtr lpCollectDataTimeout
18+
);
19+
}
20+
}

0 commit comments

Comments
 (0)