• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SafeHandles.SafePipeHandle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: NamedPipeClientStream

		public NamedPipeClientStream (PipeDirection direction, bool isAsync, bool isConnected, SafePipeHandle safePipeHandle)
			: base (direction, DefaultBufferSize)
		{
			if (IsWindows)
				impl = new Win32NamedPipeClient (this, safePipeHandle);
			else
				impl = new UnixNamedPipeClient (this, safePipeHandle);
			IsConnected = isConnected;
			InitializeHandle (safePipeHandle, true, isAsync);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:NamedPipeClientStream.cs


示例17: 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)
 {
     Interop.Sys.FileStatus status;
     int result = CheckPipeCall(Interop.Sys.FStat(safePipeHandle, out status));
     if (result == 0)
     {
         if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) != Interop.Sys.FileTypes.S_IFIFO)
         {
             throw new IOException(SR.IO_InvalidPipeHandle);
         }
     }
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:PipeStream.Unix.cs


示例18: AnonymousPipeClientStream

		public AnonymousPipeClientStream (PipeDirection direction,SafePipeHandle safePipeHandle)
			: base (direction, DefaultBufferSize)
		{
			/*
			if (IsWindows)
				impl = new Win32AnonymousPipeClient (this, safePipeHandle);
			else
				impl = new UnixAnonymousPipeClient (this, safePipeHandle);
			*/

			InitializeHandle (safePipeHandle, false, false);
			IsConnected = true;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:AnonymousPipeClientStream.cs


示例19: TryGetNumberOfServerInstances

        internal static bool TryGetNumberOfServerInstances(SafePipeHandle handle, out int numberOfServerInstances)
        {
            int serverInstances;

            if (GetNamedPipeHandleState(handle, IntPtr.Zero, out serverInstances, IntPtr.Zero, IntPtr.Zero, null, 0))
            {
                numberOfServerInstances = serverInstances;
                return true;
            }

            numberOfServerInstances = 0;
            return false;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:Interop.cs


示例20: InvalidPipeHandle_Throws

        public static void InvalidPipeHandle_Throws()
        {
            using (AnonymousPipeServerStream dummyserver = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws<ArgumentNullException>("serverSafePipeHandle", () => new AnonymousPipeServerStream(PipeDirection.Out, null, dummyserver.ClientSafePipeHandle));

                Assert.Throws<ArgumentNullException>("clientSafePipeHandle", () => new AnonymousPipeServerStream(PipeDirection.Out, dummyserver.SafePipeHandle, null));

                SafePipeHandle pipeHandle = new SafePipeHandle(new IntPtr(-1), true);
                Assert.Throws<ArgumentException>("serverSafePipeHandle", () => new AnonymousPipeServerStream(PipeDirection.Out, pipeHandle, dummyserver.ClientSafePipeHandle));

                Assert.Throws<ArgumentException>("clientSafePipeHandle", () => new AnonymousPipeServerStream(PipeDirection.Out, dummyserver.SafePipeHandle, pipeHandle));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:AnonymousPipeTest.CreateServer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SafeHandles.SafeProcessHandle类代码示例发布时间:2022-05-26
下一篇:
C# SafeHandles.SafeNCryptKeyHandle类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap