Ejemplo n.º 1
0
        public static PipeInstance Create(PipeName pipeName, bool firstInstance, SecurityDescriptor securityDescriptor)
        {
            // parameters validation
            if (pipeName == null)
            {
                throw new ArgumentNullException("pipeName", "Pipe name must be specified");
            }
            if (!pipeName.IsLocal)
            {
                throw new ArgumentException("Could not bind to the remote pipe");
            }

            PipeNative.SecurityAttributes secAttrs = new PipeNative.SecurityAttributes();
            secAttrs.SecurityDescriptor = (securityDescriptor == null ? IntPtr.Zero : securityDescriptor.Handle);
            secAttrs.InheritHandle      = true;

            // try to create pipe
            IntPtr handle = PipeNative.CreateNamedPipe(pipeName.ToString(),
                                                       PipeNative.PIPE_ACCESS_DUPLEX | PipeNative.FILE_FLAG_OVERLAPPED | (firstInstance ? PipeNative.FILE_FLAG_FIRST_PIPE_INSTANCE : 0),
                                                       PipeNative.PIPE_TYPE_BYTE | PipeNative.PIPE_READMODE_BYTE | PipeNative.PIPE_WAIT,
                                                       PipeNative.PIPE_UNLIMITED_INSTANCES,
                                                       OutBufferSize,
                                                       InBufferSize,
                                                       PipeNative.NMPWAIT_USE_DEFAULT_WAIT,
                                                       secAttrs);

            if (handle == Win32.InvalidHandle)
            {
                throw new PipeIOException(Marshal.GetLastWin32Error(), "Could not create pipe: " + pipeName);
            }
            else
            {
                return(new PipeInstance(pipeName, handle, false));
            }
        }
Ejemplo n.º 2
0
		public static PipeInstance Create(PipeName pipeName, bool firstInstance, SecurityDescriptor securityDescriptor)
		{
			// parameters validation
			if (pipeName == null)
				throw new ArgumentNullException("pipeName", "Pipe name must be specified");
			if (!pipeName.IsLocal)
				throw new ArgumentException("Could not bind to the remote pipe");

			PipeNative.SecurityAttributes secAttrs = new PipeNative.SecurityAttributes();
			secAttrs.SecurityDescriptor = (securityDescriptor == null ? IntPtr.Zero : securityDescriptor.Handle);
			secAttrs.InheritHandle = true;

			// try to create pipe
			IntPtr handle = PipeNative.CreateNamedPipe(pipeName.ToString(),
				PipeNative.PIPE_ACCESS_DUPLEX | PipeNative.FILE_FLAG_OVERLAPPED | (firstInstance ? PipeNative.FILE_FLAG_FIRST_PIPE_INSTANCE : 0),
				PipeNative.PIPE_TYPE_BYTE | PipeNative.PIPE_READMODE_BYTE | PipeNative.PIPE_WAIT,
				PipeNative.PIPE_UNLIMITED_INSTANCES,
				OutBufferSize,
				InBufferSize,
				PipeNative.NMPWAIT_USE_DEFAULT_WAIT,
				secAttrs);

			if (handle == Win32.InvalidHandle)
			{
				throw new PipeIOException(Marshal.GetLastWin32Error(), "Could not create pipe: " + pipeName);
			}
			else
			{
				return new PipeInstance(pipeName, handle, false);
			}
		}