diff --git a/src/core/IronPython.Modules/_winapi.cs b/src/core/IronPython.Modules/_winapi.cs index d26d03ec6..6568c5467 100644 --- a/src/core/IronPython.Modules/_winapi.cs +++ b/src/core/IronPython.Modules/_winapi.cs @@ -15,6 +15,8 @@ using IronPython.Runtime; using IronPython.Runtime.Operations; +using Microsoft.Win32.SafeHandles; + [assembly: PythonModule("_winapi", typeof(IronPython.Modules.PythonWinApi), PlatformsAttribute.PlatformFamily.Windows)] namespace IronPython.Modules { [SupportedOSPlatform("windows")] @@ -234,6 +236,16 @@ public static int WaitForSingleObject(BigInteger handle, int dwMilliseconds) { return WaitForSingleObjectPI(new IntPtr((long)handle), dwMilliseconds); } + public static void SetNamedPipeHandleState(BigInteger named_pipe, object? mode, object? max_collection_count, object? collect_data_timeout) { + if (max_collection_count is not null) throw new NotImplementedException(); + if (collect_data_timeout is not null) throw new NotImplementedException(); + var pipeHandle = new SafePipeHandle(new IntPtr((long)named_pipe), false); + int m = Converter.ConvertToInt32(mode); + var result = Interop.Kernel32.SetNamedPipeHandleState(pipeHandle, ref m, IntPtr.Zero, IntPtr.Zero); + + if (!result) throw PythonNT.GetLastWin32Error(); + } + #endregion #region struct's and enum's diff --git a/src/core/IronPython/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs b/src/core/IronPython/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs new file mode 100644 index 000000000..fb6d24b1d --- /dev/null +++ b/src/core/IronPython/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Win32.SafeHandles; + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop { + internal static partial class Kernel32 { + [DllImport(Libraries.Kernel32, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern unsafe bool SetNamedPipeHandleState( + SafePipeHandle hNamedPipe, + ref int lpMode, + IntPtr lpMaxCollectionCount, + IntPtr lpCollectDataTimeout + ); + } +}