当前位置: 首页>>代码示例>>C#>>正文


C# SafePipeHandle.SetHandle方法代码示例

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafePipeHandle.SetHandle方法的典型用法代码示例。如果您正苦于以下问题:C# SafePipeHandle.SetHandle方法的具体用法?C# SafePipeHandle.SetHandle怎么用?C# SafePipeHandle.SetHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.SafeHandles.SafePipeHandle的用法示例。


在下文中一共展示了SafePipeHandle.SetHandle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Open

 /// <summary>Opens the specified file with the requested flags and mode.</summary>
 /// <param name="path">The path to the file.</param>
 /// <param name="flags">The flags with which to open the file.</param>
 /// <param name="mode">The mode for opening the file.</param>
 /// <returns>A SafeFileHandle for the opened file.</returns>
 internal static SafePipeHandle Open(string path, Interop.libc.OpenFlags flags, int mode)
 {
     // SafePipeHandle wraps a file descriptor rather than a pointer, and a file descriptor is always 4 bytes
     // rather than being pointer sized, which means we can't utilize the runtime's ability to marshal safe handles.
     // Ideally this would be a constrained execution region, but we don't have access to PrepareConstrainedRegions.
     // We still use a finally block to house the code that opens the file and stores the handle in hopes
     // of making it as non-interruptable as possible.  The SafePipeHandle is also allocated first to avoid
     // the allocation after getting the file descriptor but before storing it.
     SafePipeHandle handle = new SafePipeHandle();
     try { }
     finally
     {
         int fd;
         while (Interop.CheckIo(fd = Interop.libc.open(path, flags, mode))) ;
         Debug.Assert(fd >= 0);
         handle.SetHandle((IntPtr)fd);
     }
     return handle;
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:24,代码来源:SafePipeHandle.Unix.cs

示例2: CreateAnonymousPipe

        /// <summary>Creates an anonymous pipe.</summary>
        /// <param name="inheritability">The inheritability to try to use.  This may not always be honored, depending on platform.</param>
        /// <param name="reader">The resulting reader end of the pipe.</param>
        /// <param name="writer">The resulting writer end of the pipe.</param>
        internal static unsafe void CreateAnonymousPipe(
            HandleInheritability inheritability, out SafePipeHandle reader, out SafePipeHandle writer)
        {
            // Allocate the safe handle objects prior to calling pipe/pipe2, in order to help slightly in low-mem situations
            reader = new SafePipeHandle();
            writer = new SafePipeHandle();

            // Create the OS pipe
            int* fds = stackalloc int[2];
            CreateAnonymousPipe(inheritability, fds);

            // Store the file descriptors into our safe handles
            reader.SetHandle(fds[Interop.Sys.ReadEndOfPipe]);
            writer.SetHandle(fds[Interop.Sys.WriteEndOfPipe]);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:19,代码来源:PipeStream.Unix.cs


注:本文中的Microsoft.Win32.SafeHandles.SafePipeHandle.SetHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。