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


C# SafeHandles.SafePipeHandle类代码示例

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


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

示例1: StartClient

 protected static void StartClient(PipeDirection direction, SafePipeHandle clientPipeHandle)
 {
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(direction, clientPipeHandle))
     {
         DoStreamOperations(client);
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:AnonymousPipeTestBase.cs

示例2: Create

        private void Create(PipeDirection direction, HandleInheritability inheritability, int bufferSize)
        {
            Debug.Assert(direction != PipeDirection.InOut, "Anonymous pipe direction shouldn't be InOut");
            // Ignore bufferSize.  It's optional, and the fcntl F_SETPIPE_SZ for changing it is Linux specific.

            // Use pipe or pipe2 to create our anonymous pipe
            int[] fds = new int[2];
            unsafe
            {
                fixed (int* fdsptr = fds)
                {
                    CreatePipe(inheritability, fdsptr);
                }
            }

            // Create SafePipeHandles for each end of the pipe.  Which ends goes with server and which goes with
            // client depends on the direction of the pipe.
            SafePipeHandle serverHandle = new SafePipeHandle(
                (IntPtr)fds[direction == PipeDirection.In ? Interop.libc.ReadEndOfPipe : Interop.libc.WriteEndOfPipe], 
                ownsHandle: true);
            SafePipeHandle clientHandle = new SafePipeHandle(
                (IntPtr)fds[direction == PipeDirection.In ? Interop.libc.WriteEndOfPipe : Interop.libc.ReadEndOfPipe], 
                ownsHandle: true);

            // We're connected.  Finish initialization using the newly created handles.
            InitializeHandle(serverHandle, isExposed: false, isAsync: false);
            _clientHandle = clientHandle;
            State = PipeState.Connected;
        }
开发者ID:jsalvadorp,项目名称:corefx,代码行数:29,代码来源:AnonymousPipeServerStream.Unix.cs

示例3: GetNamedPipeInfo

 internal static extern bool GetNamedPipeInfo(
     SafePipeHandle hNamedPipe,
     IntPtr lpFlags,
     IntPtr lpOutBufferSize,
     out int lpInBufferSize,
     IntPtr lpMaxInstances
 );
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:Interop.GetNamedPipeInfo.cs

示例4: AnonymousPipeServerStream

        public AnonymousPipeServerStream(PipeDirection direction, SafePipeHandle serverSafePipeHandle, SafePipeHandle clientSafePipeHandle)
            : base(direction, 0)
        {
            if (direction == PipeDirection.InOut)
            {
                throw new NotSupportedException(SR.NotSupported_AnonymousPipeUnidirectional);
            }
            if (serverSafePipeHandle == null)
            {
                throw new ArgumentNullException("serverSafePipeHandle");
            }
            if (clientSafePipeHandle == null)
            {
                throw new ArgumentNullException("clientSafePipeHandle");
            }
            if (serverSafePipeHandle.IsInvalid)
            {
                throw new ArgumentException(SR.Argument_InvalidHandle, "serverSafePipeHandle");
            }
            if (clientSafePipeHandle.IsInvalid)
            {
                throw new ArgumentException(SR.Argument_InvalidHandle, "clientSafePipeHandle");
            }
            ValidateHandleIsPipe(serverSafePipeHandle);
            ValidateHandleIsPipe(clientSafePipeHandle);

            InitializeHandle(serverSafePipeHandle, true, false);

            _clientHandle = clientSafePipeHandle;
            _clientHandleExposed = true;
            State = PipeState.Connected;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:32,代码来源:AnonymousPipeServerStream.cs

示例5: AnonymousPipeClientStream

        public AnonymousPipeClientStream(PipeDirection direction, String pipeHandleAsString)
            : base(direction, 0)
        {
            if (direction == PipeDirection.InOut)
            {
                throw new NotSupportedException(SR.NotSupported_AnonymousPipeUnidirectional);
            }
            if (pipeHandleAsString == null)
            {
                throw new ArgumentNullException("pipeHandleAsString");
            }

            // Initialize SafePipeHandle from String and check if it's valid. First see if it's parseable
            long result = 0;
            bool parseable = long.TryParse(pipeHandleAsString, out result);
            if (!parseable)
            {
                throw new ArgumentException(SR.Argument_InvalidHandle, "pipeHandleAsString");
            }

            // next check whether the handle is invalid
            SafePipeHandle safePipeHandle = new SafePipeHandle((IntPtr)result, true);
            if (safePipeHandle.IsInvalid)
            {
                throw new ArgumentException(SR.Argument_InvalidHandle, "pipeHandleAsString");
            }

            Init(direction, safePipeHandle);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:29,代码来源:AnonymousPipeClientStream.cs

示例6: AnonymousPipeServerStream

 public AnonymousPipeServerStream(PipeDirection direction, SafePipeHandle serverSafePipeHandle, SafePipeHandle clientSafePipeHandle) : base(direction, 0)
 {
     if (direction == PipeDirection.InOut)
     {
         throw new NotSupportedException(System.SR.GetString("NotSupported_AnonymousPipeUnidirectional"));
     }
     if (serverSafePipeHandle == null)
     {
         throw new ArgumentNullException("serverSafePipeHandle");
     }
     if (clientSafePipeHandle == null)
     {
         throw new ArgumentNullException("clientSafePipeHandle");
     }
     if (serverSafePipeHandle.IsInvalid)
     {
         throw new ArgumentException(System.SR.GetString("Argument_InvalidHandle"), "serverSafePipeHandle");
     }
     if (clientSafePipeHandle.IsInvalid)
     {
         throw new ArgumentException(System.SR.GetString("Argument_InvalidHandle"), "clientSafePipeHandle");
     }
     if (Microsoft.Win32.UnsafeNativeMethods.GetFileType(serverSafePipeHandle) != 3)
     {
         throw new IOException(System.SR.GetString("IO_IO_InvalidPipeHandle"));
     }
     if (Microsoft.Win32.UnsafeNativeMethods.GetFileType(clientSafePipeHandle) != 3)
     {
         throw new IOException(System.SR.GetString("IO_IO_InvalidPipeHandle"));
     }
     base.InitializeHandle(serverSafePipeHandle, true, false);
     this.m_clientHandle = clientSafePipeHandle;
     this.m_clientHandleExposed = true;
     base.State = PipeState.Connected;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:AnonymousPipeServerStream.cs

示例7: GetNamedPipeHandleState

 internal static extern bool GetNamedPipeHandleState(
     SafePipeHandle hNamedPipe,
     IntPtr lpState,
     out int lpCurInstances,
     IntPtr lpMaxCollectionCount,
     IntPtr lpCollectDataTimeout,
     IntPtr lpUserName,
     int nMaxUserNameSize);
开发者ID:Czapek83,项目名称:corefx,代码行数:8,代码来源:Interop.GetNamedPipeHandleState.cs

示例8: InitializeBufferSize

 internal void InitializeBufferSize(SafePipeHandle handle, int bufferSize)
 {
     if (bufferSize > 0)
     {
         SysCall(handle, (fd, _, size) => Interop.libc.fcntl(fd, Interop.libc.FcntlCommands.F_SETPIPE_SZ, size), 
             IntPtr.Zero, bufferSize);
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:PipeStream.Linux.cs

示例9: InOutPipeDirection_Throws_NotSupportedException

        public static void InOutPipeDirection_Throws_NotSupportedException()
        {
            // Anonymous pipes can't be made with PipeDirection.InOut
            Assert.Throws<NotSupportedException>(() => new AnonymousPipeClientStream(PipeDirection.InOut, "123"));

            SafePipeHandle pipeHandle = new SafePipeHandle(new IntPtr(-1), true);
            Assert.Throws<NotSupportedException>(() => new AnonymousPipeClientStream(PipeDirection.InOut, pipeHandle));
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:AnonymousPipeTest.CreateClient.cs

示例10: ValidateHandleIsPipe

 /// <summary>Throws an exception if the supplied handle does not represent a valid pipe.</summary>
 /// <param name="safePipeHandle">The handle to validate.</param>
 internal void ValidateHandleIsPipe(SafePipeHandle safePipeHandle)
 {
     // Check that this handle is infact a handle to a pipe.
     if (Interop.mincore.GetFileType(safePipeHandle) != Interop.mincore.FileTypes.FILE_TYPE_PIPE)
     {
         throw new IOException(SR.IO_InvalidPipeHandle);
     }
 }
开发者ID:nelsonsar,项目名称:corefx,代码行数:10,代码来源:PipeStream.Windows.cs

示例11: DuplicateHandle

 internal static extern bool DuplicateHandle(
     IntPtr hSourceProcessHandle,
     SafePipeHandle hSourceHandle,
     IntPtr hTargetProcessHandle,
     out SafePipeHandle lpTargetHandle,
     uint dwDesiredAccess,
     [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
     uint dwOptions);
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:Interop.DuplicateHandle_IntPtr.cs

示例12: StartClient

 public static void StartClient(PipeDirection direction, SafePipeHandle clientPipeHandle)
 {
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(direction, clientPipeHandle))
     {
         DoStreamOperations(client);
     }
     // If you don't see this message that means that this task crashed.
     Console.WriteLine("*** Client operations suceedeed. ***");
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:9,代码来源:AnonymousPipesSimpleTest.cs

示例13: InitializeAsyncHandle

 /// <summary>Initializes the handle to be used asynchronously.</summary>
 /// <param name="handle">The handle.</param>
 private void InitializeAsyncHandle(SafePipeHandle handle)
 {
     // If the handle is of async type, bind the handle to the ThreadPool so that we can use 
     // the async operations (it's needed so that our native callbacks get called).
     if (!ThreadPool.BindHandle(handle))
     {
         throw new IOException(SR.IO_BindHandleFailed);
     }
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:11,代码来源:PipeStream.Windows.cs

示例14: Init

 private void Init(PipeDirection direction, SafePipeHandle safePipeHandle)
 {
     Debug.Assert(direction != PipeDirection.InOut, "anonymous pipes are unidirectional, caller should have verified before calling Init");
     Debug.Assert(safePipeHandle != null && !safePipeHandle.IsInvalid, "safePipeHandle must be valid");
     ValidateHandleIsPipe(safePipeHandle);
     
     InitializeHandle(safePipeHandle, true, false);
     State = PipeState.Connected;
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:AnonymousPipeClientStream.cs

示例15: Init

 private void Init(PipeDirection direction, SafePipeHandle safePipeHandle)
 {
     if (Microsoft.Win32.UnsafeNativeMethods.GetFileType(safePipeHandle) != 3)
     {
         throw new IOException(System.SR.GetString("IO_IO_InvalidPipeHandle"));
     }
     base.InitializeHandle(safePipeHandle, true, false);
     base.State = PipeState.Connected;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:AnonymousPipeClientStream.cs


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