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;
        }
 protected static void StartClient(PipeDirection direction, SafePipeHandle clientPipeHandle)
 {
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(direction, clientPipeHandle))
     {
         DoStreamOperations(client);
     }
 }
 public static void NullServerName_Throws_ArgumentNullException(PipeDirection direction)
 {
     Assert.Throws<ArgumentNullException>("serverName", () => new NamedPipeClientStream(null, "client1"));
     Assert.Throws<ArgumentNullException>("serverName", () => new NamedPipeClientStream(null, "client1", direction));
     Assert.Throws<ArgumentNullException>("serverName", () => new NamedPipeClientStream(null, "client1", direction, PipeOptions.None));
     Assert.Throws<ArgumentNullException>("serverName", () => new NamedPipeClientStream(null, "client1", direction, PipeOptions.None, TokenImpersonationLevel.None));
 }
Beispiel #4
0
        private void Init(PipeDirection direction, PipeTransmissionMode transmissionMode, int outBufferSize)
        {
            Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
            Debug.Assert(transmissionMode >= PipeTransmissionMode.Byte && transmissionMode <= PipeTransmissionMode.Message, "transmissionMode is out of range");
            Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");

            // always defaults to this until overridden
            _readMode = transmissionMode;
            _transmissionMode = transmissionMode;

            _pipeDirection = direction;

            if ((_pipeDirection & PipeDirection.In) != 0)
            {
                _canRead = true;
            }
            if ((_pipeDirection & PipeDirection.Out) != 0)
            {
                _canWrite = true;
            }

            _outBufferSize = outBufferSize;

            // This should always default to true
            _isMessageComplete = true;

            _state = PipeState.WaitingToConnect;
            _streamAsyncHelper = new StreamAsyncHelper(this);
        }
        private NamedPipeServerStream(String pipeName, PipeDirection direction, int maxNumberOfServerInstances,
                PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
                HandleInheritability inheritability)
            : base(direction, transmissionMode, outBufferSize)
        {
            if (pipeName == null)
            {
                throw new ArgumentNullException("pipeName");
            }
            if (pipeName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_NeedNonemptyPipeName);
            }
            if ((options & ~(PipeOptions.WriteThrough | PipeOptions.Asynchronous)) != 0)
            {
                throw new ArgumentOutOfRangeException("options", SR.ArgumentOutOfRange_OptionsInvalid);
            }
            if (inBufferSize < 0)
            {
                throw new ArgumentOutOfRangeException("inBufferSize", SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            // win32 allows fixed values of 1-254 or 255 to mean max allowed by system. We expose 255 as -1 (unlimited)
            // through the MaxAllowedServerInstances constant. This is consistent e.g. with -1 as infinite timeout, etc
            if ((maxNumberOfServerInstances < 1 || maxNumberOfServerInstances > 254) && (maxNumberOfServerInstances != MaxAllowedServerInstances))
            {
                throw new ArgumentOutOfRangeException("maxNumberOfServerInstances", SR.ArgumentOutOfRange_MaxNumServerInstances);
            }
            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable)
            {
                throw new ArgumentOutOfRangeException("inheritability", SR.ArgumentOutOfRange_HandleInheritabilityNoneOrInheritable);
            }

            Create(pipeName, direction, maxNumberOfServerInstances, transmissionMode,
                options, inBufferSize, outBufferSize, inheritability);
        }
 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;
 }
        private NamedPipeServerStream(String pipeName, PipeDirection direction, int maxNumberOfServerInstances,
                PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
                HandleInheritability inheritability)
            : base(direction, transmissionMode, outBufferSize)
        {
            if (pipeName == null)
            {
                throw new ArgumentNullException("pipeName");
            }
            if (pipeName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_NeedNonemptyPipeName);
            }
            if ((options & ~(PipeOptions.WriteThrough | PipeOptions.Asynchronous)) != 0)
            {
                throw new ArgumentOutOfRangeException("options", SR.ArgumentOutOfRange_OptionsInvalid);
            }
            if (inBufferSize < 0)
            {
                throw new ArgumentOutOfRangeException("inBufferSize", SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            ValidateMaxNumberOfServerInstances(maxNumberOfServerInstances);
            // inheritability will always be None since this private constructor is only called from other constructors from which
            // inheritability is always set to None. Desktop has a public constructor to allow setting it to something else, but Core
            // doesnt.
            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable)
            {
                throw new ArgumentOutOfRangeException("inheritability", SR.ArgumentOutOfRange_HandleInheritabilityNoneOrInheritable);
            }

            Create(pipeName, direction, maxNumberOfServerInstances, transmissionMode,
                options, inBufferSize, outBufferSize, inheritability);
        }
        private void Create(string pipeName, PipeDirection direction, int maxNumberOfServerInstances,
                PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
                HandleInheritability inheritability)
        {
            Debug.Assert(pipeName != null && pipeName.Length != 0, "fullPipeName is null or empty");
            Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
            Debug.Assert(inBufferSize >= 0, "inBufferSize is negative");
            Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");
            Debug.Assert((maxNumberOfServerInstances >= 1) || (maxNumberOfServerInstances == MaxAllowedServerInstances), "maxNumberOfServerInstances is invalid");
            Debug.Assert(transmissionMode >= PipeTransmissionMode.Byte && transmissionMode <= PipeTransmissionMode.Message, "transmissionMode is out of range");

            if (transmissionMode == PipeTransmissionMode.Message)
            {
                throw new PlatformNotSupportedException(SR.PlatformNotSupported_MessageTransmissionMode);
            }

            // NOTE: We don't have a good way to enforce maxNumberOfServerInstances, and don't currently try.
            // It's a Windows-specific concept.

            _path = GetPipePath(".", pipeName);
            _direction = direction;
            _options = options;
            _inBufferSize = inBufferSize;
            _outBufferSize = outBufferSize;
            _inheritability = inheritability;
        }
        private void Create(PipeDirection direction, HandleInheritability inheritability, int bufferSize)
        {
            Debug.Assert(direction != PipeDirection.InOut, "Anonymous pipe direction shouldn't be InOut");
            Debug.Assert(bufferSize >= 0, "bufferSize is negative");

            throw NotImplemented.ByDesign; // TODO: Implement this
        }
        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);
        }
 public static void EmptyStringServerName_Throws_ArgumentException(PipeDirection direction)
 {
     Assert.Throws<ArgumentException>(() => new NamedPipeClientStream("", "client1"));
     Assert.Throws<ArgumentException>(() => new NamedPipeClientStream("", "client1", direction));
     Assert.Throws<ArgumentException>(() => new NamedPipeClientStream("", "client1", direction, PipeOptions.None));
     Assert.Throws<ArgumentException>(() => new NamedPipeClientStream("", "client1", direction, PipeOptions.None, TokenImpersonationLevel.None));
 }
        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;
        }
        private void Create(string pipeName, PipeDirection direction, int maxNumberOfServerInstances,
                PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
                HandleInheritability inheritability)
        {
            Debug.Assert(pipeName != null && pipeName.Length != 0, "fullPipeName is null or empty");
            Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
            Debug.Assert(inBufferSize >= 0, "inBufferSize is negative");
            Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");
            Debug.Assert((maxNumberOfServerInstances >= 1) || (maxNumberOfServerInstances == MaxAllowedServerInstances), "maxNumberOfServerInstances is invalid");
            Debug.Assert(transmissionMode >= PipeTransmissionMode.Byte && transmissionMode <= PipeTransmissionMode.Message, "transmissionMode is out of range");

            if (transmissionMode == PipeTransmissionMode.Message)
            {
                throw new PlatformNotSupportedException();
            }

            // NOTE: We don't have a good way to enforce maxNumberOfServerInstances, and don't currently try.
            // It's a Windows-specific concept.

            // Make sure the FIFO exists, but don't open it until WaitForConnection is called.
            _path = GetPipePath(".", pipeName);
            while (true)
            {
                int result = Interop.libc.mkfifo(_path, (int)Interop.libc.Permissions.S_IRWXU);
                if (result == 0)
                {
                    // The FIFO was successfully created - note that although we create the FIFO here, we don't
                    // ever delete it. If we remove the FIFO we could invalidate other servers that also use it. 
                    // See #2764 for further discussion.
                    break;
                }

                Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
                if (errorInfo.Error == Interop.Error.EINTR)
                {
                    // interrupted; try again
                    continue;
                }
                else if (errorInfo.Error == Interop.Error.EEXIST)
                {
                    // FIFO already exists; nothing more to do
                    break;
                }
                else
                {
                    // something else; fail
                    throw Interop.GetExceptionForIoErrno(errorInfo, _path);
                }
            }

            // Store the rest of the creation arguments.  They'll be used when we open the connection
            // in WaitForConnection.
            _direction = direction;
            _options = options;
            _inBufferSize = inBufferSize;
            _outBufferSize = outBufferSize;
            _inheritability = inheritability;
        }
 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. ***");
 }
 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;
 }
 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;
 }
 public static void NullPipeName_Throws_ArgumentNullException(PipeDirection direction)
 {
     Assert.Throws<ArgumentNullException>("pipeName", () => new NamedPipeServerStream(null));
     Assert.Throws<ArgumentNullException>("pipeName", () => new NamedPipeServerStream(null, direction));
     Assert.Throws<ArgumentNullException>("pipeName", () => new NamedPipeServerStream(null, direction, 2));
     Assert.Throws<ArgumentNullException>("pipeName", () => new NamedPipeServerStream(null, direction, 3, PipeTransmissionMode.Byte));
     Assert.Throws<ArgumentNullException>("pipeName", () => new NamedPipeServerStream(null, direction, 3, PipeTransmissionMode.Byte, PipeOptions.None));
     Assert.Throws<ArgumentNullException>("pipeName", () => new NamedPipeServerStream(null, direction, 3, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0));
 }
 public static void ZeroLengthPipeName_Throws_ArgumentException(PipeDirection direction)
 {
     Assert.Throws<ArgumentException>(() => new NamedPipeServerStream(""));
     Assert.Throws<ArgumentException>(() => new NamedPipeServerStream("", direction));
     Assert.Throws<ArgumentException>(() => new NamedPipeServerStream("", direction, 2));
     Assert.Throws<ArgumentException>(() => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte));
     Assert.Throws<ArgumentException>(() => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte, PipeOptions.None));
     Assert.Throws<ArgumentException>(() => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0));
 }
 public static void ReservedPipeName_Throws_ArgumentOutOfRangeException(PipeDirection direction)
 {
     const string reservedName = "anonymous";
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeServerStream(reservedName));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeServerStream(reservedName, direction));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeServerStream(reservedName, direction, 1));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeServerStream(reservedName, direction, 1, PipeTransmissionMode.Byte));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeServerStream(reservedName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.None));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeServerStream(reservedName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0));}
 public static void ReservedPipeName_Throws_ArgumentOutOfRangeException(PipeDirection direction)
 {
     const string serverName = ".";
     const string reservedName = "anonymous";
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeClientStream(reservedName));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeClientStream(serverName, reservedName));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeClientStream(serverName, reservedName, direction));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeClientStream(serverName, reservedName, direction, PipeOptions.None));
     Assert.Throws<ArgumentOutOfRangeException>("pipeName", () => new NamedPipeClientStream(serverName, reservedName, direction, PipeOptions.None, TokenImpersonationLevel.Impersonation));
 }
Beispiel #21
0
		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);
		}
 protected PipeStream(PipeDirection direction, int bufferSize)
 {
     if ((direction < PipeDirection.In) || (direction > PipeDirection.InOut))
     {
         throw new ArgumentOutOfRangeException("direction", System.SR.GetString("ArgumentOutOfRange_DirectionModeInOutOrInOut"));
     }
     if (bufferSize < 0)
     {
         throw new ArgumentOutOfRangeException("bufferSize", System.SR.GetString("ArgumentOutOfRange_NeedNonNegNum"));
     }
     this.Init(direction, PipeTransmissionMode.Byte, bufferSize);
 }
Beispiel #23
0
        public AnonymousPipeServerStream(PipeDirection direction, HandleInheritability inheritability, int bufferSize)
            : base(direction, bufferSize) {
            if (direction == PipeDirection.InOut) {
                throw new NotSupportedException(SR.GetString(SR.NotSupported_AnonymousPipeUnidirectional));
            }
            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable) {
                throw new ArgumentOutOfRangeException("inheritability", SR.GetString(SR.ArgumentOutOfRange_HandleInheritabilityNoneOrInheritable));
            }

            UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = PipeStream.GetSecAttrs(inheritability);
            Create(direction, secAttrs, bufferSize);
        }
        private void Create(string pipeName, PipeDirection direction, int maxNumberOfServerInstances,
                PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
                HandleInheritability inheritability)
        {
            Debug.Assert(pipeName != null && pipeName.Length != 0, "fullPipeName is null or empty");
            Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
            Debug.Assert(inBufferSize >= 0, "inBufferSize is negative");
            Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");
            Debug.Assert((maxNumberOfServerInstances >= 1 && maxNumberOfServerInstances <= 254) || (maxNumberOfServerInstances == MaxAllowedServerInstances), "maxNumberOfServerInstances is invalid");
            Debug.Assert(transmissionMode >= PipeTransmissionMode.Byte && transmissionMode <= PipeTransmissionMode.Message, "transmissionMode is out of range");

            throw NotImplemented.ByDesign; // TODO: Implement this
        }
		internal static PipeAccessRights ToAccessRights (PipeDirection direction)
		{
			switch (direction) {
			case PipeDirection.In:
				return PipeAccessRights.ReadData;
			case PipeDirection.Out:
				return PipeAccessRights.WriteData;
			case PipeDirection.InOut:
				return PipeAccessRights.ReadData | PipeAccessRights.WriteData;
			default:
				throw new ArgumentOutOfRangeException ();
			}
		}
		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;
		}
Beispiel #27
0
        protected PipeStream(PipeDirection direction, int bufferSize)
        {
            if (direction < PipeDirection.In || direction > PipeDirection.InOut)
            {
                throw new ArgumentOutOfRangeException("direction", SR.ArgumentOutOfRange_DirectionModeInOutOrInOut);
            }
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException("bufferSize", SR.ArgumentOutOfRange_NeedNonNegNum);
            }

            Init(direction, PipeTransmissionMode.Byte, bufferSize);
        }
        public AnonymousPipeServerStream(PipeDirection direction, HandleInheritability inheritability, int bufferSize)
            : base(direction, bufferSize)
        {
            if (direction == PipeDirection.InOut)
            {
                throw new NotSupportedException(SR.NotSupported_AnonymousPipeUnidirectional);
            }
            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable)
            {
                throw new ArgumentOutOfRangeException("inheritability", SR.ArgumentOutOfRange_HandleInheritabilityNoneOrInheritable);
            }

            Create(direction, inheritability, bufferSize);
        }
		public AnonymousPipeServerStream (PipeDirection direction, HandleInheritability inheritability, int bufferSize, PipeSecurity pipeSecurity)
			: base (direction, bufferSize)
		{
			if (direction == PipeDirection.InOut)
				throw new NotSupportedException ("Anonymous pipe direction can only be either in or out.");

			if (IsWindows)
				impl = new Win32AnonymousPipeServer (this, direction, inheritability, bufferSize, pipeSecurity);
			else
				impl = new UnixAnonymousPipeServer (this, direction, inheritability, bufferSize);

			InitializeHandle (impl.Handle, false, false);
			IsConnected = true;
		}
Beispiel #30
0
		public NamedPipeServerStream (string pipeName, PipeDirection direction, int maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize, PipeSecurity pipeSecurity, HandleInheritability inheritability, PipeAccessRights additionalAccessRights)
			: base (direction, transmissionMode, outBufferSize)
		{
			if (pipeSecurity != null)
				throw ThrowACLException ();
			var rights = ToAccessRights (direction) | additionalAccessRights;
			// FIXME: reject some rights declarations (for ACL).

			if (IsWindows)
				impl = new Win32NamedPipeServer (this, pipeName, maxNumberOfServerInstances, transmissionMode, rights, options, inBufferSize, outBufferSize, inheritability);
			else
				impl = new UnixNamedPipeServer (this, pipeName, maxNumberOfServerInstances, transmissionMode, rights, options, inBufferSize, outBufferSize, inheritability);

			InitializeHandle (impl.Handle, false, (options & PipeOptions.Asynchronous) != PipeOptions.None);
		}
Beispiel #31
0
 /// <summary>Initializes a new instance of the <see cref="AnonymousPipeServerStreamAdapter" /> class from the specified pipe handles.</summary>
 /// <param name="direction">One of the enumeration values that determines the direction of the pipe.Anonymous pipes can only be in one direction, so <paramref name="direction" /> cannot be set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</param>
 /// <param name="serverSafePipeHandle">A safe handle for the pipe that this <see cref="AnonymousPipeServerStreamAdapter" /> object will encapsulate.</param>
 /// <param name="clientSafePipeHandle">A safe handle for the <see cref="T:System.IO.Pipes.AnonymousPipeClientStream" /> object.</param>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="serverSafePipeHandle" /> or <paramref name="clientSafePipeHandle" /> is an invalid handle.</exception>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="serverSafePipeHandle" /> or <paramref name="clientSafePipeHandle" /> is <see langword="null" />.</exception>
 /// <exception cref="T:System.NotSupportedException">
 /// <paramref name="direction" /> is set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</exception>
 /// <exception cref="T:System.IO.IOException">An I/O error, such as a disk error, has occurred.-or-The stream has been closed.</exception>
 public AnonymousPipeServerStreamAdapter(PipeDirection direction, [NotNull] SafePipeHandle serverSafePipeHandle, [NotNull] SafePipeHandle clientSafePipeHandle)
     : this(new AnonymousPipeServerStream(direction, serverSafePipeHandle, clientSafePipeHandle))
 {
 }
Beispiel #32
0
 /// <summary>Initializes a new instance of the <see cref="AnonymousPipeClientStreamAdapter" /> class from the specified handle.</summary>
 /// <param name="direction">One of the enumeration values that determines the direction of the pipe.Anonymous pipes can only be in one direction, so <paramref name="direction" /> cannot be set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</param>
 /// <param name="safePipeHandle">A safe handle for the pipe that this <see cref="AnonymousPipeClientStreamAdapter" /> object will encapsulate.</param>
 /// <exception cref="ArgumentException">
 /// <paramref name="safePipeHandle " />is not a valid handle.</exception>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="safePipeHandle" /> is <see langword="null" />.</exception>
 /// <exception cref="NotSupportedException">
 /// <paramref name="direction" /> is set to <see cref="PipeDirection.InOut" />.</exception>
 /// <exception cref="IOException">An I/O error, such as a disk error, has occurred.-or-The stream has been closed.</exception>
 public AnonymousPipeClientStreamAdapter(PipeDirection direction, [NotNull] SafePipeHandle safePipeHandle)
     : this(new AnonymousPipeClientStream(direction, safePipeHandle))
 {
 }
Beispiel #33
0
 public static void InvalidPipeOptions_Throws_ArgumentOutOfRangeException(PipeDirection direction)
 {
     Assert.Throws <ArgumentOutOfRangeException>("options", () => new NamedPipeServerStream("temp1", direction, 1, PipeTransmissionMode.Byte, (PipeOptions)255));
     Assert.Throws <ArgumentOutOfRangeException>("options", () => new NamedPipeServerStream("tempx", direction, 1, PipeTransmissionMode.Byte, (PipeOptions)255, 0, 0));
 }
 public AnonymousPipeClientStream(PipeDirection direction, string pipeHandleAsString)
     : this(direction, ToSafePipeHandle(pipeHandleAsString))
 {
 }
Beispiel #35
0
 public NamedPipeServerStream(string pipeName, PipeDirection direction)
     : this(pipeName, direction, 1)
 {
 }
Beispiel #36
0
 public NamedPipeServerStream(string pipeName, PipeDirection direction, int maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options)
     : this(pipeName, direction, maxNumberOfServerInstances, transmissionMode, options, DefaultBufferSize, DefaultBufferSize)
 {
 }
 public AnonymousPipeServerStream(PipeDirection direction, HandleInheritability inheritability)
     : this(direction, inheritability, 0)
 {
 }
 public PipeVisualState(PipeDirection pipeDirection, ConduitLayer conduitLayer)
 {
     PipeDirection = pipeDirection;
     ConduitLayer  = conduitLayer;
 }
Beispiel #39
0
 [PlatformSpecific(TestPlatforms.Windows)] // accessing SafePipeHandle on Unix fails for a non-connected stream
 public static void Windows_CreateFromAlreadyBoundHandle_Throws_ArgumentException(PipeDirection direction)
 {
     // The pipe is already bound
     using (var pipe = new NamedPipeServerStream(GetUniquePipeName(), direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
     {
         Assert.Throws <ArgumentException>(() => new NamedPipeServerStream(direction, true, true, pipe.SafePipeHandle));
     }
 }
Beispiel #40
0
        [PlatformSpecific(TestPlatforms.Windows)] // accessing SafePipeHandle on Unix fails for a non-connected stream
        public static void Windows_CreateFromDisposedServerHandle_Throws_ObjectDisposedException(PipeDirection direction)
        {
            // The pipe is closed when we try to make a new Stream with it
            var            pipe   = new NamedPipeServerStream(GetUniquePipeName(), direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
            SafePipeHandle handle = pipe.SafePipeHandle;

            pipe.Dispose();
            Assert.Throws <ObjectDisposedException>(() => new NamedPipeServerStream(direction, true, true, pipe.SafePipeHandle).Dispose());
        }
Beispiel #41
0
        public static void InvalidPipeHandle_Throws_ArgumentException(PipeDirection direction)
        {
            SafePipeHandle pipeHandle = new SafePipeHandle(new IntPtr(-1), true);

            Assert.Throws <ArgumentException>("safePipeHandle", () => new NamedPipeServerStream(direction, false, true, pipeHandle));
        }
Beispiel #42
0
 public static void NullPipeHandle_Throws_ArgumentNullException(PipeDirection direction)
 {
     Assert.Throws <ArgumentNullException>("safePipeHandle", () => new NamedPipeServerStream(direction, false, true, null));
 }
Beispiel #43
0
 /// <summary>Initializes a new instance of the <see cref="AnonymousPipeClientStreamAdapter" /> class with the specified pipe direction and a string representation of the pipe handle.</summary>
 /// <param name="direction">One of the enumeration values that determines the direction of the pipe.Anonymous pipes can only be in one direction, so <paramref name="direction" /> cannot be set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</param>
 /// <param name="pipeHandleAsString">A string that represents the pipe handle.</param>
 /// <exception cref="ArgumentException">
 /// <paramref name="pipeHandleAsString" /> is an invalid handle.</exception>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="pipeHandleAsString" /> is <see langword="null" />.</exception>
 /// <exception cref="NotSupportedException">
 /// <paramref name="direction" /> is set to <see cref="PipeDirection.InOut" />.</exception>
 public AnonymousPipeClientStreamAdapter(PipeDirection direction, [NotNull] string pipeHandleAsString)
     : this(new AnonymousPipeClientStream(direction, pipeHandleAsString))
 {
 }
Beispiel #44
0
 protected PipeStream(PipeDirection direction, int bufferSize)
     : this(direction, PipeTransmissionMode.Byte, bufferSize)
 {
 }
Beispiel #45
0
        public NamedPipeServerStream(string pipeName, PipeDirection direction, int maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize)
#if MOBILE
            : base(direction, inBufferSize)
        {
            throw new NotImplementedException();
        }
Beispiel #46
0
        public void InvalidReadMode_Throws_ArgumentOutOfRangeException(PipeDirection serverDirection, PipeDirection clientDirection)
        {
            string pipeName = GetUniquePipeName();

            using (var server = new NamedPipeServerStream(pipeName, serverDirection, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                using (var client = new NamedPipeClientStream(".", pipeName, clientDirection))
                {
                    Task clientConnect = client.ConnectAsync();
                    server.WaitForConnection();
                    clientConnect.Wait();

                    Assert.Throws <ArgumentOutOfRangeException>(() => server.ReadMode = (PipeTransmissionMode)999);
                    Assert.Throws <ArgumentOutOfRangeException>(() => client.ReadMode = (PipeTransmissionMode)999);
                }
        }
Beispiel #47
0
 public NamedPipeServerStream(string pipeName, PipeDirection direction, int maxNumberOfServerInstances, PipeTransmissionMode transmissionMode)
     : this(pipeName, direction, maxNumberOfServerInstances, transmissionMode, PipeOptions.None)
 {
 }
Beispiel #48
0
 public NamedPipeServerStream(String pipeName, PipeDirection direction)
     : this(pipeName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0, HandleInheritability.None)
 {
 }
 internal static NamedPipeClientStream CreateNamedPipeClient(string serverName, string pipeName, PipeDirection direction, PipeOptions options) =>
 new NamedPipeClientStream(serverName, pipeName, direction, options);
Beispiel #50
0
 // Creates the anonymous pipe.
 private void Create(PipeDirection direction, HandleInheritability inheritability, int bufferSize)
 {
     Create(direction, inheritability, bufferSize, null);
 }
Beispiel #51
0
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 서버 생성하기 - CreateServer(pipeName, pipeDirection)

        /// <summary>
        /// 서버 생성하기
        /// </summary>
        /// <param name="pipeName">파이프명</param>
        /// <param name="pipeDirection">파이프 방향</param>
        /// <returns>명명 파이프</returns>
        public static NamedPipe CreateServer(string pipeName, PipeDirection pipeDirection)
        {
            NamedPipe pipe = new NamedPipe(pipeName, pipeDirection);

            return(pipe);
        }
Beispiel #52
0
 public static void InvalidTransmissionMode_Throws_ArgumentOutOfRangeException(PipeDirection direction)
 {
     Assert.Throws <ArgumentOutOfRangeException>("transmissionMode", () => new NamedPipeServerStream("temp1", direction, 1, (PipeTransmissionMode)123));
     Assert.Throws <ArgumentOutOfRangeException>("transmissionMode", () => new NamedPipeServerStream("temp1", direction, 1, (PipeTransmissionMode)123, PipeOptions.None));
     Assert.Throws <ArgumentOutOfRangeException>("transmissionMode", () => new NamedPipeServerStream("tempx", direction, 1, (PipeTransmissionMode)123, PipeOptions.None, 0, 0));
 }
Beispiel #53
0
 /// <summary>Initializes a new instance of the <see cref="AnonymousPipeServerStreamAdapter" /> class with the specified pipe direction, inheritability mode, buffer size, and pipe security.</summary>
 /// <param name="direction">One of the enumeration values that determines the direction of the pipe.Anonymous pipes can only be in one direction, so <paramref name="direction" /> cannot be set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</param>
 /// <param name="inheritability">One of the enumeration values that determines whether the underlying handle can be inherited by child processes.</param>
 /// <param name="bufferSize">The size of the buffer. This value must be greater than or equal to 0. </param>
 /// <param name="pipeSecurity">An object that determines the access control and audit security for the pipe.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// <paramref name="inheritability" /> is not set to either <see cref="F:System.IO.HandleInheritability.None" /> or <see cref="F:System.IO.HandleInheritability.Inheritable" />.-or-
 /// <paramref name="bufferSize" /> is less than 0.</exception>
 /// <exception cref="T:System.NotSupportedException">
 /// <paramref name="direction" /> is set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</exception>
 public AnonymousPipeServerStreamAdapter(PipeDirection direction, HandleInheritability inheritability, int bufferSize, PipeSecurity pipeSecurity)
     : this(new AnonymousPipeServerStream(direction, inheritability, bufferSize, pipeSecurity))
 {
 }
Beispiel #54
0
 /// <summary>
 /// 생성자
 /// </summary>
 /// <param name="pipeName">파이프명</param>
 /// <param name="pipeDirection">파이프 방향</param>
 private NamedPipe(string pipeName, PipeDirection pipeDirection) : this()
 {
     this.pipeName      = string.Format(PIPE_NAME, pipeName);
     this.pipeDirection = pipeDirection;
 }
Beispiel #55
0
        public static NamedPipeClientStream CreatePipeStream(String pipe_name, String host_name, int pipe_connect_timeout, PipeDirection direction = PipeDirection.InOut)
        {
            NamedPipeClientStream pipeClientStream = null;

            try
            {
                _logger.LogMsg(Level.Debug, String.Format("Creating .NET NamedPipeClientStream object for {0}", pipe_name));
                pipeClientStream =
                    new NamedPipeClientStream(
                        host_name,
                        pipe_name,
                        direction,
                        PipeOptions.Asynchronous, // TO DO: is Asynchronous the correct option?
                        System.Security.Principal.TokenImpersonationLevel.Impersonation,
                        HandleInheritability.Inheritable);


                // Connect to the pipe
                _logger.LogMsg(Level.Debug, String.Format("Attempting to connect to pipe [{0}] on host [{1}].", pipe_name, host_name));
                pipeClientStream.Connect(pipe_connect_timeout);
                _logger.LogMsg(Level.Info, String.Format("Pipe connection successful: [{0}].", pipe_name));
                _logger.LogMsg(Level.Debug, String.Format("There are currently {0} pipe server instances open.", pipeClientStream.NumberOfServerInstances));
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("Error in CreatePipeStream(): " + ex.Message);
                throw ex;
            }

            return(pipeClientStream);
        }
Beispiel #56
0
 /// <summary>Initializes a new instance of the <see cref="AnonymousPipeServerStreamAdapter" /> class with the specified pipe direction and inheritability mode.</summary>
 /// <param name="direction">One of the enumeration values that determines the direction of the pipe.Anonymous pipes can only be in one direction, so <paramref name="direction" /> cannot be set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</param>
 /// <param name="inheritability">One of the enumeration values that determines whether the underlying handle can be inherited by child processes. Must be set to either <see cref="F:System.IO.HandleInheritability.None" /> or <see cref="F:System.IO.HandleInheritability.Inheritable" />. </param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// <paramref name="inheritability" /> is not set to either <see cref="F:System.IO.HandleInheritability.None" /> or <see cref="F:System.IO.HandleInheritability.Inheritable" />.</exception>
 /// <exception cref="T:System.NotSupportedException">
 /// <paramref name="direction" /> is set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</exception>
 public AnonymousPipeServerStreamAdapter(PipeDirection direction, HandleInheritability inheritability)
     : this(new AnonymousPipeServerStream(direction, inheritability))
 {
 }
 public NamedPipeClientStreamWrapper(string v, string token, PipeDirection inOut)
 {
     _pipeClientStream = new NamedPipeClientStream(v, token, inOut);
 }
Beispiel #58
0
 /// <summary>Initializes a new instance of the <see cref="AnonymousPipeServerStreamAdapter" /> class with the specified pipe direction.</summary>
 /// <param name="direction">One of the enumeration values that determines the direction of the pipe.Anonymous pipes can only be in one direction, so <paramref name="direction" /> cannot be set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</param>
 /// <exception cref="T:System.NotSupportedException">
 /// <paramref name="direction" /> is set to <see cref="F:System.IO.Pipes.PipeDirection.InOut" />.</exception>
 public AnonymousPipeServerStreamAdapter(PipeDirection direction)
     : this(new AnonymousPipeServerStream(direction))
 {
 }
Beispiel #59
0
 public static void InvalidBufferSize_Throws_ArgumentOutOfRangeException(PipeDirection direction)
 {
     Assert.Throws <ArgumentOutOfRangeException>("inBufferSize", () => new NamedPipeServerStream("temp2", direction, 1, PipeTransmissionMode.Byte, PipeOptions.None, -1, 0));
     Assert.Throws <ArgumentOutOfRangeException>("outBufferSize", () => new NamedPipeServerStream("temp2", direction, 1, PipeTransmissionMode.Byte, PipeOptions.None, 0, -123));
 }
Beispiel #60
0
 public NamedPipeClientStream(string serverName, string pipeName, PipeDirection direction,
                              PipeOptions options, TokenImpersonationLevel impersonationLevel)
     : this(serverName, pipeName, direction, options, impersonationLevel, HandleInheritability.None)
 {
 }