コード例 #1
0
 public static void ServerWriteNegativeOffsetThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
     {
         ConnectedPipeWriteNegativeOffsetThrows(server);
     }
 }
コード例 #2
0
 public static void ServerWriteBufferNullThrows()
 {
     // force different constructor path
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None))
     {
         ConnectedPipeWriteBufferNullThrows(server);
     }
 }
コード例 #3
0
 public static void ServerWriteBufferNullThrows()
 {
     // force different constructor path
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None))
     {
         Assert.Throws<ArgumentNullException>(() => server.Write(null, 0, 1));
         Assert.Throws<ArgumentNullException>(() => NotReachable(server.WriteAsync(null, 0, 1)));
     }
 }
コード例 #4
0
        public static void ServerReadModeThrows()
        {
            // force different constructor path
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream())
            {
                Assert.Throws<ArgumentOutOfRangeException>(() => server.ReadMode = (PipeTransmissionMode)999);

                Assert.Throws<NotSupportedException>(() => server.ReadMode = PipeTransmissionMode.Message);
            }
        }
コード例 #5
0
        public static void ServerBadPipeDirectionThrows()
        {
            Assert.Throws<NotSupportedException>(() => new AnonymousPipeServerStream(PipeDirection.InOut));
            Assert.Throws<NotSupportedException>(() => new AnonymousPipeServerStream(PipeDirection.InOut, HandleInheritability.None));
            Assert.Throws<NotSupportedException>(() => new AnonymousPipeServerStream(PipeDirection.InOut, HandleInheritability.None, 500));

            using (AnonymousPipeServerStream dummyserver = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws<NotSupportedException>(() => new AnonymousPipeServerStream(PipeDirection.InOut, dummyserver.SafePipeHandle, null));
            }
        }
コード例 #6
0
        public static void ServerWriteNegativeOffsetThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws<ArgumentOutOfRangeException>(() => server.Write(new byte[5], -1, 1));

                // array is checked first
                Assert.Throws<ArgumentNullException>(() => server.Write(null, -1, 1));
                Assert.Throws<ArgumentNullException>(() => NotReachable(server.WriteAsync(null, -1, 1)));
            }
        }
コード例 #7
0
        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));
            }
        }
コード例 #8
0
        public static void DisposeLocalCopyOfClientHandle_BeforeServerRead()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
                {
                    byte[] sent = new byte[] { 123 };
                    byte[] received = new byte[] { 0 };
                    client.Write(sent, 0, 1);

                    server.DisposeLocalCopyOfClientHandle();

                    Assert.Equal(1, server.Read(received, 0, 1));
                    Assert.Equal(sent[0], received[0]);
                }
            }
        }
コード例 #9
0
        public static void ClonedClient_ActsAsOriginalClient()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                using (AnonymousPipeClientStream clientBase = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
                {
                    using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, clientBase.SafePipeHandle))
                    {
                        Assert.True(server.IsConnected);
                        Assert.True(client.IsConnected);

                        byte[] sent     = new byte[] { 123 };
                        byte[] received = new byte[] { 0 };
                        server.Write(sent, 0, 1);

                        Assert.Equal(1, client.Read(received, 0, 1));
                        Assert.Equal(sent[0], received[0]);
                    }
                }
            }
        }
コード例 #10
0
ファイル: Pipes.cs プロジェクト: aik-jahoda/runtime
        public async Task AnonymousPipeReadViaFileStream(bool asyncReads)
        {
            using (var server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Task serverTask = server.WriteAsync(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 6);

                using (var client = new FileStream(new SafeFileHandle(server.ClientSafePipeHandle.DangerousGetHandle(), false), FileAccess.Read, bufferSize: 3))
                {
                    var arr = new byte[1];
                    for (int i = 0; i < 6; i++)
                    {
                        Assert.Equal(1, asyncReads ?
                                     await client.ReadAsync(arr, 0, 1) :
                                     client.Read(arr, 0, 1));
                        Assert.Equal(i, arr[0]);
                    }
                }

                await serverTask;
            }
        }
コード例 #11
0
        public PipeServer(string filename)
        {
            Process = new Process {
                StartInfo = { FileName = filename }
            };

            Pipe =
                new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable)
            {
                ReadMode = PipeTransmissionMode.Byte
            };
            Process.StartInfo.Arguments       = Pipe.GetClientHandleAsString();
            Process.StartInfo.UseShellExecute = false;
            Process.Start();
            Pipe.DisposeLocalCopyOfClientHandle();

            PipeWriter = new StreamWriter(Pipe)
            {
                AutoFlush = true
            };
        }
コード例 #12
0
        public void PingPong()
        {
            // Create two anonymous pipes, one for each direction of communication.
            // Then spawn another process to communicate with.
            using (var outbound = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
            using (var inbound = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
            using (var remote = RemoteInvoke(PingPong_OtherProcess, outbound.GetClientHandleAsString(), inbound.GetClientHandleAsString()))
            {
                // Close our local copies of the handles now that we've passed them of to the other process
                outbound.DisposeLocalCopyOfClientHandle();
                inbound.DisposeLocalCopyOfClientHandle();

                // Ping-pong back and forth by writing then reading bytes one at a time.
                for (byte i = 0; i < 10; i++)
                {
                    outbound.WriteByte(i);
                    int received = inbound.ReadByte();
                    Assert.Equal(i, received);
                }
            }
        }
コード例 #13
0
        static void Main(string[] args)
        {
            using (AnonymousPipeServerStream pipedServer = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Thread child = new Thread(new ParameterizedThreadStart(childThread));
                child.Start(pipedServer.GetClientHandleAsString());

                using (StreamWriter sw = new StreamWriter(pipedServer))
                {
                    var data = string.Empty;
                    sw.AutoFlush = true;
                    while (!data.Equals("quit", StringComparison.InvariantCultureIgnoreCase))
                    {
                        pipedServer.WaitForPipeDrain();
                        Console.WriteLine("SERVER : ");
                        data = Console.ReadLine();
                        sw.WriteLine(data);
                    }
                }
            }
        }
コード例 #14
0
        public void PingPong()
        {
            // Create two anonymous pipes, one for each direction of communication.
            // Then spawn another process to communicate with.
            using (var outbound = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
                using (var inbound = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
                    using (var remote = RemoteInvoke(new Func <string, string, int>(PingPong_OtherProcess), outbound.GetClientHandleAsString(), inbound.GetClientHandleAsString()))
                    {
                        // Close our local copies of the handles now that we've passed them of to the other process
                        outbound.DisposeLocalCopyOfClientHandle();
                        inbound.DisposeLocalCopyOfClientHandle();

                        // Ping-pong back and forth by writing then reading bytes one at a time.
                        for (byte i = 0; i < 10; i++)
                        {
                            outbound.WriteByte(i);
                            int received = inbound.ReadByte();
                            Assert.Equal(i, received);
                        }
                    }
        }
コード例 #15
0
        public static void ClonedClient_ActsAsOriginalClient()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                using (AnonymousPipeClientStream clientBase = new AnonymousPipeClientStream(PipeDirection.In, server.GetClientHandleAsString()))
                {
                    using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, clientBase.SafePipeHandle))
                    {
                        Assert.True(server.IsConnected);
                        Assert.True(client.IsConnected);

                        byte[] sent = new byte[] { 123 };
                        byte[] received = new byte[] { 0 };
                        server.Write(sent, 0, 1);

                        Assert.Equal(1, client.Read(received, 0, 1));
                        Assert.Equal(sent[0], received[0]);
                    }
                }
            }
        }
コード例 #16
0
        public static void ClonedServer_ActsAsOriginalServer()
        {
            using (AnonymousPipeServerStream serverBase = new AnonymousPipeServerStream(PipeDirection.Out))
                using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, serverBase.SafePipeHandle, serverBase.ClientSafePipeHandle))
                {
                    Assert.True(server.IsConnected);
                    using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
                    {
                        Assert.True(server.IsConnected);
                        Assert.True(client.IsConnected);

                        byte[] sent     = new byte[] { 123 };
                        byte[] received = new byte[] { 0 };
                        server.Write(sent, 0, 1);

                        Assert.Equal(1, client.Read(received, 0, 1));
                        Assert.Equal(sent[0], received[0]);
                    }
                    Assert.Throws <IOException>(() => server.WriteByte(5));
                }
        }
コード例 #17
0
        public void Connect()
        {
            Process process = new Process();

            process.StartInfo.FileName = @"F:\Temp\vs2017----\ConsoleApp\ConsoleApp\bin\Debug\ConsoleApp.exe";

            //创建匿名管道流实例,
            using (AnonymousPipeServerStream pipeStream =
                       new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
            {
                //将句柄传递给子进程
                process.StartInfo.Arguments       = pipeStream.GetClientHandleAsString();
                process.StartInfo.UseShellExecute = false;
                process.Start();

                // 判断进程是否启动
                Process[] vProcesses = Process.GetProcesses();
                foreach (Process vProcess in vProcesses)
                {
                    if (vProcess.ProcessName.Equals("ConsoleApp",
                                                    StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }

                //销毁子进程的客户端句柄?
                pipeStream.DisposeLocalCopyOfClientHandle();

                using (StreamWriter sw = new StreamWriter(pipeStream))
                {
                    sw.AutoFlush = true;
                    //向匿名管道中写入内容
                    sw.WriteLine("fdgfdgdgdfg");
                }
            }

            process.WaitForExit();
            process.Close();
        }
コード例 #18
0
        private static T Launcher <T>(T connectLine, string filePath, bool dotnet = false, string args = "")
            where T : MessageLine
        {
            connectLine.IsLauncher = true;
            var pipeIn  = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
            var pipeOut = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);

            string connectHandlesArgs = $"-connectline {pipeOut.GetClientHandleAsString()}:{pipeIn.GetClientHandleAsString()}";

            connectLine.process = new Process();
            if (dotnet)
            {
                connectLine.process.StartInfo.FileName  = "dotnet";
                connectLine.process.StartInfo.Arguments = $"{filePath} {connectHandlesArgs} {args}".Trim();
            }
            else
            {
                connectLine.process.StartInfo.FileName  = filePath;
                connectLine.process.StartInfo.Arguments = $"{connectHandlesArgs} {args}".Trim();
            }
            connectLine.process.StartInfo.UseShellExecute = false;

            connectLine.pipeIn           = pipeIn;
            connectLine.pipeOut          = pipeOut;
            connectLine.reader           = new StreamReader(pipeIn);
            connectLine.writer           = new StreamWriter(pipeOut);
            connectLine.writer.AutoFlush = true;
            connectLine.writer.WriteLine(Markers.SYNC);

            connectLine.Run(() => {
                connectLine.Timer();
                connectLine.process.Start();
                pipeOut.DisposeLocalCopyOfClientHandle();
                pipeIn.DisposeLocalCopyOfClientHandle();
                connectLine.Await();
                connectLine.Work();
            });

            return(connectLine);
        }
コード例 #19
0
ファイル: ConsoleRedirector.cs プロジェクト: msavva/pigraphs
        //private StreamWriter _consoleStandardOut;

        private ConsoleRedirector(ProgressChangedEventHandler handler, bool forceConsoleRedirection)
        {
            bool ret;

            _forceConsoleRedirection = forceConsoleRedirection;

            if (!_forceConsoleRedirection)
            {
                //Make sure Console._out is initialized before we redirect stdout, so the redirection won't affect it
                TextWriter temp = Console.Out;
            }

            AnonymousPipeClientStream client;

            _worker = new BackgroundWorker();
            _worker.ProgressChanged      += handler;
            _worker.DoWork               += _worker_DoWork;
            _worker.WorkerReportsProgress = true;

            _stdout = GetStdHandle(STD_OUTPUT_HANDLE);

            _sync   = new Mutex();
            _buffer = new char[BUFFER_SIZE];

            _outServer = new AnonymousPipeServerStream(PipeDirection.Out);
            client     = new AnonymousPipeClientStream(PipeDirection.In, _outServer.ClientSafePipeHandle);
            Debug.Assert(_outServer.IsConnected);
            _outClient = new StreamReader(client, Encoding.Default);
            ret        = SetStdHandle(STD_OUTPUT_HANDLE, _outServer.SafePipeHandle.DangerousGetHandle());
            Debug.Assert(ret);

            if (_forceConsoleRedirection)
            {
                ResetConsoleOutStream(); //calls to Console.Write/WriteLine will now get made against the redirected stream
            }

            _worker.RunWorkerAsync(_outClient);

            _timer = new System.Threading.Timer(flush, null, PERIOD, PERIOD);
        }
コード例 #20
0
ファイル: Monitor.cs プロジェクト: ellisonch/ProcessGuardian
        internal async Task RunOnce(int id)
        {
            KillProcess();

            using (var process = GetProcess(_pathAndFilename))
                using (var pipeServer = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable)) {
                    process.StartInfo.Environment.Add(PgClientLib.EnvironmentKeyName, pipeServer.GetClientHandleAsString());

                    process.Start();
                    // The DisposeLocalCopyOfClientHandle method should be called after the client handle has been passed to the client. If this method is not called, the AnonymousPipeServerStream object will not receive notice when the client disposes of its PipeStream object.
                    pipeServer.DisposeLocalCopyOfClientHandle();

                    await InnerLoop(pipeServer, id).ConfigureAwait(false);

                    try {
                        if (!process.HasExited)
                        {
                            process.Kill();
                        }
                    } catch { }
                }
        }
コード例 #21
0
        public static void BufferSizeRoundtripping()
        {
            // On systems other than Linux, setting the buffer size of the server will only set
            // set the buffer size of the client if the flow of the pipe is towards the client i.e.
            // the client is defined with PipeDirection.In

            int desiredBufferSize = 10;

            using (var server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, desiredBufferSize))
                using (var client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
                {
                    Assert.Equal(desiredBufferSize, server.OutBufferSize);
                    Assert.Equal(desiredBufferSize, client.InBufferSize);
                }

            using (var server = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.None, desiredBufferSize))
                using (var client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
                {
                    Assert.Equal(desiredBufferSize, server.InBufferSize);
                    Assert.Equal(0, client.OutBufferSize);
                }
        }
コード例 #22
0
        public async Task SendAsync(Process p, string value)
        {
            using (AnonymousPipeServerStream pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
            {
                try
                {
                    Console.WriteLine("[SERVER] Setting ReadMode to \"Message\".");
                    pipeServer.ReadMode = PipeTransmissionMode.Message;
                }
                catch (NotSupportedException e)
                {
                    Console.WriteLine("[SERVER] Exception:\n    {0}", e.Message);
                }

                Console.WriteLine("[SERVER] Current TransmissionMode: {0}.",
                                  pipeServer.TransmissionMode);

                Console.WriteLine(p.StartInfo.Arguments +
                                  pipeServer.GetClientHandleAsString());

                pipeServer.DisposeLocalCopyOfClientHandle();

                try
                {
                    using (StreamWriter sw = new StreamWriter(pipeServer))
                    {
                        sw.AutoFlush = true;
                        await sw.WriteLineAsync("SYNC");

                        pipeServer.WaitForPipeDrain();
                        await sw.WriteLineAsync(value);
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("[SERVER] Error: {0}", e.Message);
                }
            }
        }
コード例 #23
0
        public static void Start(ProcessStartInfo processInfo)
        {
            writePipe = new AnonymousPipeServerStream(PipeDirection.Out, System.IO.HandleInheritability.Inheritable);
            readPipe  = new AnonymousPipeServerStream(PipeDirection.In, System.IO.HandleInheritability.Inheritable);

            writeStream = writePipe; readStream = readPipe;

            PrivateStart();

            processInfo.Arguments += " -pipes " + writePipe.GetClientHandleAsString() + " " + readPipe.GetClientHandleAsString();
            try
            {
                Process = Process.Start(processInfo);
            }
            catch
            {
                DebugConsole.ThrowError($"Failed to start ChildServerRelay Process. File: {processInfo.FileName}, arguments: {processInfo.Arguments}");
                throw;
            }

            localHandlesDisposed = false;
        }
コード例 #24
0
        private bool WaitForConnectionFromProcess(AnonymousPipeServerStream clientToServerStream,
                                                  AnonymousPipeServerStream serverToClientStream,
                                                  int nodeProcessId, long hostHandshake, long clientHandshake)
        {
            try
            {
                CommunicationsUtilities.Trace("Attempting to handshake with PID {0}", nodeProcessId);

                CommunicationsUtilities.Trace("Writing handshake to pipe");
                serverToClientStream.WriteLongForHandshake(hostHandshake);

                CommunicationsUtilities.Trace("Reading handshake from pipe");
                long handshake = clientToServerStream.ReadLongForHandshake();

                if (handshake != clientHandshake)
                {
                    CommunicationsUtilities.Trace("Handshake failed. Received {0} from client not {1}. Probably the client is a different MSBuild build.", handshake, clientHandshake);
                    throw new InvalidOperationException();
                }

                // We got a connection.
                CommunicationsUtilities.Trace("Successfully connected got connection from PID {0}...!", nodeProcessId);
                return(true);
            }
            catch (Exception ex)
            {
                if (ExceptionHandling.IsCriticalException(ex))
                {
                    throw;
                }

                CommunicationsUtilities.Trace("Failed to get connection from PID {0}. {1}", nodeProcessId, ex.ToString());

                clientToServerStream.Dispose();
                serverToClientStream.Dispose();

                return(false);
            }
        }
コード例 #25
0
        static void Main(string[] args)
        {
            for (int i = 0; i < 2; i++)
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                using (AnonymousPipeServerStream apcs = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
                {
                    using (StreamWriter sw = new StreamWriter(apcs))
                    {
                        Process p = new Process();
                        psi.FileName        = "..\\..\\..\\Hijo\\bin\\Debug\\Hijo.exe";
                        psi.UseShellExecute = false;
                        psi.Arguments       = apcs.GetClientHandleAsString();
                        p.StartInfo         = psi;

                        p.Start();
                        sw.WriteLine(i);
                    }
                }
            }
            Console.ReadLine();
        }
コード例 #26
0
        private void OpenPipes()
        {
            if (inPipeID == null)
            {
                pipeIn   = pipeServerIn = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
                inPipeID = pipeServerIn.GetClientHandleAsString();
            }
            else
            {
                pipeIn = new AnonymousPipeClientStream(PipeDirection.In, inPipeID);
            }

            if (outPipeID == null)
            {
                pipeOut   = pipeServerOut = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);
                outPipeID = pipeServerOut.GetClientHandleAsString();
            }
            else
            {
                pipeOut = new AnonymousPipeClientStream(PipeDirection.Out, outPipeID);
            }
        }
コード例 #27
0
        public void Start()
        {
            _logsManagerPipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);

            _pipeServerStreamWriter = TextWriter.Synchronized(new StreamWriter(_logsManagerPipeServer)
            {
                AutoFlush = true
            });

            _logsAnalyzerProcess = new Process();

            _logsAnalyzerProcess.StartInfo.FileName = _analyzerAssemblyFileName + ".exe";

            // Pass the client process a handle to the server.
            _logsAnalyzerProcess.StartInfo.Arguments = _logsManagerPipeServer.GetClientHandleAsString();

            _logsAnalyzerProcess.StartInfo.UseShellExecute = false;

            _logsAnalyzerProcess.Start();

            _logsManagerPipeServer.DisposeLocalCopyOfClientHandle();
        }
コード例 #28
0
        /// <summary>
        /// Gets a writer used to upload data to a Google Cloud Storage object. Used by Set-Content.
        /// </summary>
        /// <param name="path">The path of the object to upload to.</param>
        /// <returns>The writer.</returns>
        public IContentWriter GetContentWriter(string path)
        {
            var    gcsPath = GcsPath.Parse(path);
            Object body    = new Object
            {
                Name   = gcsPath.ObjectPath,
                Bucket = gcsPath.Bucket
            };
            var inputStream  = new AnonymousPipeServerStream(PipeDirection.Out);
            var outputStream = new AnonymousPipeClientStream(PipeDirection.In, inputStream.ClientSafePipeHandle);
            var contentType  = ((GcsGetContentWriterDynamicParameters)DynamicParameters).ContentType ?? GcsCmdlet.UTF8TextMimeType;

            ObjectsResource.InsertMediaUpload request =
                Service.Objects.Insert(body, gcsPath.Bucket, outputStream, contentType);
            request.UploadAsync();
            IContentWriter contentWriter = new GcsContentWriter(inputStream);

            // Force the bucket models to refresh with the potentially new object.
            BucketModels.Clear();
            TelemetryReporter.ReportSuccess(nameof(GoogleCloudStorageProvider), nameof(GetContentWriter));
            return(contentWriter);
        }
コード例 #29
0
ファイル: Pipe.cs プロジェクト: jonathan-lemos/backup4
        private async Task <Result <AggregateException> > _executeNoTransformations()
        {
            if (_inputFunc == null || _outputFunc == null)
            {
                throw new InvalidOperationException(
                          "An input source and an output sink must both be set with SetInput/SetOutput respectively.");
            }

            var server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, BufferSize);
            var client = new AnonymousPipeClientStream(server.GetClientHandleAsString());

            var inputTask = Task.Run(async() =>
            {
                try
                {
                    return(await _inputFunc(server));
                }
                finally
                {
                    await server.DisposeAsync();
                }
            });

            var outputTask = Task.Run(async() =>
            {
                try
                {
                    return(await _outputFunc(client));
                }
                finally
                {
                    await client.DisposeAsync();
                }
            });

            // server.DisposeLocalCopyOfClientHandle();

            return((await Task.WhenAll(inputTask, outputTask)).Combine());
        }
コード例 #30
0
        public void SimpleMessageTest()
        {
            var pipeServer = new AnonymousPipeServerStream(PipeDirection.In);
            var pipeClient = new AnonymousPipeClientStream(PipeDirection.Out, pipeServer.ClientSafePipeHandle);

            try
            {
                var    ps    = new PackedStream(pipeServer, pipeClient);
                var    rdn   = new Random();
                var    data  = new byte[rdn.Next(10, 1024)];
                byte[] nData = null;
                var    mre   = new ManualResetEvent(false);
                rdn.NextBytes(data);

                ps.DataReceived += (s, d) =>
                {
                    nData = d.MemoryStream.ToArray();

                    mre.Set();
                };

                ps.Write(new MemoryStream(data));

                mre.WaitOne();

                Assert.AreEqual(data.Length, nData.Length);

                for (var i = 0; i < data.Length; i++)
                {
                    Assert.AreEqual(data[i], nData[i]);
                }
            }
            finally
            {
                pipeServer.Close();
                pipeClient.Close();
            }
        }
コード例 #31
0
ファイル: Monitor.cs プロジェクト: ellisonch/ProcessGuardian
        private async Task InnerLoop(AnonymousPipeServerStream pipeServer, int id)
        {
            _lastSeen = DateTime.Now;
            var readTask = ReadDateTime(pipeServer);

            while (true)
            {
                var latency = DateTime.Now - _lastSeen;
                if (latency > _timeBeforeRestart)
                {
                    Log($"{id}: Need to restart, not seen fast enough ({latency.TotalMilliseconds}ms)");
                    return;
                }
                else
                {
                    // Log($"{id}: Refreshed fast enough ({latency.TotalMilliseconds}ms)");
                }

                var sw         = Stopwatch.StartNew();
                var taskResult = await TimeoutAfter(readTask, _pollResolution);

                if (taskResult.HasValue)
                {
                    // if the task completed, handle the result and create a new task
                    var now = taskResult.Value;
                    _lastSeen = now;
                    readTask  = ReadDateTime(pipeServer);

                    Log($"{id}: Read dt of {now}; restart delay is {_currentRestartDelay}");
                }

                var newCurrent = _currentRestartDelay.Subtract(new TimeSpan(sw.ElapsedTicks / 4));
                if (newCurrent >= _minRestartDelay)
                {
                    _currentRestartDelay = newCurrent;
                }
            }
        }
コード例 #32
0
        /// <summary>
        /// 匿名管道服务端
        /// </summary>
        static void AnonymousPipeServer()
        {
            var pipeClient = new Process();

            pipeClient.StartInfo.FileName = @"D:\CSharpCode\MyDemo\ConsoleApp2\bin\Debug\ConsoleApp2.exe";

            using (var pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
            {
                Console.WriteLine($"[SERVER] Current TransmissionMode: {pipeServer.TransmissionMode}");

                pipeClient.StartInfo.Arguments       = pipeServer.GetClientHandleAsString();
                pipeClient.StartInfo.UseShellExecute = false;
                pipeClient.Start();

                pipeServer.DisposeLocalCopyOfClientHandle();

                try
                {
                    using (var sw = new StreamWriter(pipeServer))
                    {
                        sw.AutoFlush = true;
                        sw.WriteLine("SYNC");
                        pipeServer.WaitForPipeDrain();
                        Console.WriteLine("[SERVER] Enter text:");
                        sw.WriteLine(Console.ReadLine());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            pipeClient.WaitForExit();
            pipeClient.Close();
            Console.WriteLine($"[SERVER] Client quit. Server terminating.");
        }
コード例 #33
0
    public static void ServerPInvokeChecks()
    {
        // calling every API related to server and client to detect any bad PInvokes
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            Task clientTask = StartClientAsync(PipeDirection.In, server.ClientSafePipeHandle);

            Console.WriteLine("server.CanRead = {0}", server.CanRead);
            Console.WriteLine("server.CanSeek = {0}", server.CanSeek);
            Console.WriteLine("server.CanTimeout = {0}", server.CanTimeout);
            Console.WriteLine("server.CanWrite = {0}", server.CanWrite);
            Console.WriteLine("server.GetClientHandleAsString() = {0}", server.GetClientHandleAsString());
            Console.WriteLine("server.IsAsync = {0}", server.IsAsync);
            Console.WriteLine("server.IsConnected = {0}", server.IsConnected);
            Console.WriteLine("server.OutBufferSize = {0}", server.OutBufferSize);
            Console.WriteLine("server.ReadMode = {0}", server.ReadMode);
            Console.WriteLine("server.SafePipeHandle = {0}", server.SafePipeHandle);
            Console.WriteLine("server.TransmissionMode = {0}", server.TransmissionMode);
            server.Write(new byte[] { 123 }, 0, 1);
            server.WriteAsync(new byte[] { 124 }, 0, 1).Wait();
            server.Flush();
            Console.WriteLine("Waiting for Pipe Drain.");
            server.WaitForPipeDrain();
            clientTask.Wait();
            server.DisposeLocalCopyOfClientHandle();
        }
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
        {
            Task clientTask = StartClientAsync(PipeDirection.Out, server.ClientSafePipeHandle);

            Console.WriteLine("server.InBufferSize = {0}", server.InBufferSize);
            byte[] readData = new byte[] { 0, 1 };
            server.Read(readData, 0, 1);
            server.ReadAsync(readData, 1, 1).Wait();
            Assert.Equal(123, readData[0]);
            Assert.Equal(124, readData[1]);
        }
    }
コード例 #34
0
        Stream OpenOutput(string gitExe, string fileName, string blobHash)
        {
            if (blobHash == null)
            {
                return(null);
            }

            AnonymousPipeServerStream pipe = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);

            StartupInfo startupInfo = new GitVersionProvider.StartupInfo();

            startupInfo.dwFlags    = STARTF_USESTDHANDLES;
            startupInfo.hStdOutput = pipe.ClientSafePipeHandle;
            startupInfo.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
            startupInfo.hStdError  = GetStdHandle(STD_ERROR_HANDLE);
            startupInfo.cb         = 16;

            PROCESS_INFORMATION procInfo;

            string commandLine = "\"" + gitExe + "\" cat-file blob " + blobHash;
            string workingDir  = Path.GetDirectoryName(fileName);

            Debug.WriteLine(workingDir + "> " + commandLine);
            const uint CREATE_NO_WINDOW = 0x08000000;

            if (!CreateProcess(null, commandLine,
                               IntPtr.Zero, IntPtr.Zero, true, CREATE_NO_WINDOW, IntPtr.Zero, workingDir, ref startupInfo,
                               out procInfo))
            {
                pipe.DisposeLocalCopyOfClientHandle();
                pipe.Close();
                return(null);
            }

            pipe.DisposeLocalCopyOfClientHandle();

            return(pipe);
        }
コード例 #35
0
ファイル: ProcessTest.cs プロジェクト: spoiledsport/corefx
        public void Process_IPC()
        {
            Process p = CreateProcess("ipc");

            using (var outbound = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
                using (var inbound = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
                {
                    p.StartInfo.Arguments += " " + outbound.GetClientHandleAsString() + " " + inbound.GetClientHandleAsString();
                    p.Start();
                    outbound.DisposeLocalCopyOfClientHandle();
                    inbound.DisposeLocalCopyOfClientHandle();

                    for (byte i = 0; i < 10; i++)
                    {
                        outbound.WriteByte(i);
                        int received = inbound.ReadByte();
                        Assert.Equal(i, received);
                    }

                    Assert.True(p.WaitForExit(WaitInMS));
                    Assert.Equal(SuccessExitCode, p.ExitCode);
                }
        }
コード例 #36
0
    public static void ServerSendsByteClientReceivesServerClone()
    {
        using (AnonymousPipeServerStream serverBase = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, serverBase.SafePipeHandle, serverBase.ClientSafePipeHandle))
            {
                Assert.True(server.IsConnected);
                using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.GetClientHandleAsString()))
                {
                    Assert.True(server.IsConnected);
                    Assert.True(client.IsConnected);

                    byte[] sent     = new byte[] { 123 };
                    byte[] received = new byte[] { 0 };
                    server.Write(sent, 0, 1);

                    Assert.Equal(1, client.Read(received, 0, 1));
                    Assert.Equal(sent[0], received[0]);
                }
                Assert.Throws <System.IO.IOException>(() => server.WriteByte(5));
            }
        }
    }
コード例 #37
0
        public static void ServerReadArrayOutOfBoundsThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                // offset out of bounds
                Assert.Throws <ArgumentException>(null, () => server.Read(new byte[1], 1, 1));

                // offset out of bounds for 0 count read
                Assert.Throws <ArgumentException>(null, () => server.Read(new byte[1], 2, 0));

                // offset out of bounds even for 0 length buffer
                Assert.Throws <ArgumentException>(null, () => server.Read(new byte[0], 1, 0));

                // combination offset and count out of bounds
                Assert.Throws <ArgumentException>(null, () => server.Read(new byte[2], 1, 2));

                // edges
                Assert.Throws <ArgumentException>(null, () => server.Read(new byte[0], int.MaxValue, 0));
                Assert.Throws <ArgumentException>(null, () => server.Read(new byte[0], int.MaxValue, int.MaxValue));

                Assert.Throws <ArgumentException>(() => server.Read(new byte[5], 3, 4));
            }
        }
コード例 #38
0
ファイル: anonym_pipe.cs プロジェクト: inwenis/stream_funs
    public static void Main()
    {
        AnonymousPipeServerStream pipeServer =
            new AnonymousPipeServerStream(PipeDirection.Out,
                                          HandleInheritability.Inheritable);
        var clientPipeHandle = pipeServer.GetClientHandleAsString();

        Console.WriteLine(clientPipeHandle);

        Process pipeClient = new Process();

        pipeClient.StartInfo.FileName        = "client.exe";
        pipeClient.StartInfo.Arguments       = clientPipeHandle;
        pipeClient.StartInfo.UseShellExecute = false;
        pipeClient.Start();

        pipeServer.DisposeLocalCopyOfClientHandle();
        pipeServer.WriteByte(45);
        pipeServer.Flush();
        Console.WriteLine("Press any key to quit");
        Console.ReadKey();
        pipeServer.Dispose();
    }
コード例 #39
0
        private void SetupAnonymousPipes()
        {
            _pipeClient.StartInfo.FileName = "Render.exe";

            _pipeServerStream = new AnonymousPipeServerStream(
                PipeDirection.Out,
                HandleInheritability.Inheritable);

            // Pass the client process a handle to the server.
            _pipeClient.StartInfo.Arguments       = _pipeServerStream.GetClientHandleAsString();
            _pipeClient.StartInfo.UseShellExecute = false;
            _pipeClient.Start();

            _pipeServerStream.DisposeLocalCopyOfClientHandle();

            _streamWriter = new StreamWriter(_pipeServerStream)
            {
                AutoFlush = true
            };

            _streamWriter.WriteLine("[SYNC]");
            _pipeServerStream.WaitForPipeDrain();
        }
コード例 #40
0
    public static void ServerSendsByteClientReceivesAsync()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            Assert.True(server.IsConnected);
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(server.GetClientHandleAsString()))
            {
                Assert.True(server.IsConnected);
                Assert.True(client.IsConnected);

                byte[] sent      = new byte[] { 123 };
                byte[] received  = new byte[] { 0 };
                Task   writeTask = server.WriteAsync(sent, 0, 1);
                writeTask.Wait();

                Task <int> readTask = client.ReadAsync(received, 0, 1);
                readTask.Wait();

                Assert.Equal(1, readTask.Result);
                Assert.Equal(sent[0], received[0]);
            }
        }
    }
コード例 #41
0
 public void MessageReadMode_Throws_NotSupportedException()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.GetClientHandleAsString()))
     {
         Assert.Throws<NotSupportedException>(() => server.ReadMode = PipeTransmissionMode.Message);
         Assert.Throws<NotSupportedException>(() => client.ReadMode = PipeTransmissionMode.Message);
     }
 }
コード例 #42
0
 public void ReadModeToByte_Accepted(PipeDirection serverDirection, PipeDirection clientDirection)
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(serverDirection))
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(clientDirection, server.GetClientHandleAsString()))
     {
         server.ReadMode = PipeTransmissionMode.Byte;
         client.ReadMode = PipeTransmissionMode.Byte;
         Assert.Equal(PipeTransmissionMode.Byte, server.ReadMode);
         Assert.Equal(PipeTransmissionMode.Byte, client.ReadMode);
     }
 }
コード例 #43
0
 public static void ClientReadArrayOutOfBoundsThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
     {
         ConnectedPipeReadArrayOutOfBoundsThrows(client);
     }
 }
コード例 #44
0
        public static void Windows_BufferSizeRoundtripping()
        {
            // On Windows, setting the buffer size of the server will only set
            // the buffer size of the client if the flow of the pipe is towards the client i.e.
            // the client is defined with PipeDirection.In

            int desiredBufferSize = 10;
            using (var server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, desiredBufferSize))
            using (var client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
            {
                Assert.Equal(desiredBufferSize, server.OutBufferSize);
                Assert.Equal(desiredBufferSize, client.InBufferSize);
            }

            using (var server = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.None, desiredBufferSize))
            using (var client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
            {
                Assert.Equal(desiredBufferSize, server.InBufferSize);
                Assert.Equal(0, client.OutBufferSize);
            }
        }
コード例 #45
0
        public static void ServerReadNegativeCountThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                Assert.Throws<System.ArgumentOutOfRangeException>(() => server.Read(new byte[5], 0, -1));

                // offset is checked before count
                Assert.Throws<ArgumentOutOfRangeException>(() => server.Read(new byte[1], -1, -1));

                // array is checked first
                Assert.Throws<ArgumentNullException>(() => server.Read(null, -1, -1));

                Assert.Throws<System.ArgumentOutOfRangeException>(() => NotReachable(server.ReadAsync(new byte[5], 0, -1)));

                // offset is checked before count
                Assert.Throws<ArgumentOutOfRangeException>(() => NotReachable(server.ReadAsync(new byte[1], -1, -1)));

                // array is checked first
                Assert.Throws<ArgumentNullException>(() => NotReachable(server.ReadAsync(null, -1, -1)));
            }
        }
コード例 #46
0
 public static void ServerReadArrayOutOfBoundsThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
     {
         ConnectedPipeReadArrayOutOfBoundsThrows(server);
     }
 }
コード例 #47
0
        public static void Linux_BufferSizeRoundtrips()
        {
            // On Linux, setting the buffer size of the server will also set the buffer size of the
            // client, regardless of the direction of the flow

            int desiredBufferSize;
            using (var server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                desiredBufferSize = server.OutBufferSize * 2;
                Assert.True(desiredBufferSize > 0);
            }

            using (var server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, desiredBufferSize))
            using (var client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
            {
                Assert.Equal(desiredBufferSize, server.OutBufferSize);
                Assert.Equal(desiredBufferSize, client.InBufferSize);
            }

            using (var server = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.None, desiredBufferSize))
            using (var client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
            {
                Assert.Equal(desiredBufferSize, server.InBufferSize);
                Assert.Equal(desiredBufferSize, client.OutBufferSize);
            }
        }
コード例 #48
0
        public static void ClientReadOnlyCancelReadTokenThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
            {

                ConnectedPipeCancelReadTokenThrows(client);
            }
        }
コード例 #49
0
        public static void ServerReadOnlyThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                Assert.Throws<NotSupportedException>(() => server.Write(new byte[5], 0, 5));

                Assert.Throws<NotSupportedException>(() => server.WriteByte(123));

                Assert.Throws<NotSupportedException>(() => server.Flush());

                Assert.Throws<NotSupportedException>(() => server.OutBufferSize);

                Assert.Throws<NotSupportedException>(() => server.WaitForPipeDrain());

                Assert.Throws<NotSupportedException>(() => NotReachable(server.WriteAsync(new byte[5], 0, 5)));
            }
        }
コード例 #50
0
        public static void ClientReadModeThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
                {
                    Assert.Throws<ArgumentOutOfRangeException>(() => client.ReadMode = (PipeTransmissionMode)999);

                    Assert.Throws<NotSupportedException>(() => client.ReadMode = PipeTransmissionMode.Message);
                }
            }
        }
コード例 #51
0
        public static void ServerUnsupportedOperationThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws<NotSupportedException>(() => server.Length);

                Assert.Throws<NotSupportedException>(() => server.SetLength(10L));

                Assert.Throws<NotSupportedException>(() => server.Position);

                Assert.Throws<NotSupportedException>(() => server.Position = 10L);

                Assert.Throws<NotSupportedException>(() => server.Seek(10L, System.IO.SeekOrigin.Begin));
            }
        }
コード例 #52
0
 public void InvalidReadMode_Throws_ArgumentOutOfRangeException()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.GetClientHandleAsString()))
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => server.ReadMode = (PipeTransmissionMode)999);
         Assert.Throws<ArgumentOutOfRangeException>(() => client.ReadMode = (PipeTransmissionMode)999);
     }
 }
コード例 #53
0
 public static void ClientWriteNegativeCountThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
     {
         ConnectedPipeWriteNegativeCountThrows(client);
     }
 }
コード例 #54
0
        public static void ServerReadArrayOutOfBoundsThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                // offset out of bounds
                Assert.Throws<ArgumentException>(null, () => server.Read(new byte[1], 1, 1));

                // offset out of bounds for 0 count read
                Assert.Throws<ArgumentException>(null, () => server.Read(new byte[1], 2, 0));

                // offset out of bounds even for 0 length buffer
                Assert.Throws<ArgumentException>(null, () => server.Read(new byte[0], 1, 0));

                // combination offset and count out of bounds
                Assert.Throws<ArgumentException>(null, () => server.Read(new byte[2], 1, 2));

                // edges
                Assert.Throws<ArgumentException>(null, () => server.Read(new byte[0], int.MaxValue, 0));
                Assert.Throws<ArgumentException>(null, () => server.Read(new byte[0], int.MaxValue, int.MaxValue));

                Assert.Throws<ArgumentException>(() => server.Read(new byte[5], 3, 4));

                // offset out of bounds
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.ReadAsync(new byte[1], 1, 1)));

                // offset out of bounds for 0 count read
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.ReadAsync(new byte[1], 2, 0)));

                // offset out of bounds even for 0 length buffer
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.ReadAsync(new byte[0], 1, 0)));

                // combination offset and count out of bounds
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.ReadAsync(new byte[2], 1, 2)));

                // edges
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.ReadAsync(new byte[0], int.MaxValue, 0)));
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.ReadAsync(new byte[0], int.MaxValue, int.MaxValue)));

                Assert.Throws<ArgumentException>(() => NotReachable(server.ReadAsync(new byte[5], 3, 4)));
            }
        }
コード例 #55
0
 public static void ServerUnsupportedOperationThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
     {
         ConnectedPipeUnsupportedOperationThrows(server);
     }
 }
コード例 #56
0
        public static void ClientReadOnlyDisconnectedPipeThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
            {
                client.Dispose();

                OtherSidePipeDisconnectWriteThrows(server);
            }
        }
コード例 #57
0
 public static void ClientUnsupportedOperationThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
     using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
     {
         ConnectedPipeUnsupportedOperationThrows(client);
     }
 }
コード例 #58
0
 public static void OSX_BufferSizeNotSupported()
 {
     int desiredBufferSize = 10;
     using (var server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, desiredBufferSize))
     using (var client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
     {
         Assert.Throws<PlatformNotSupportedException>(() => server.OutBufferSize);
         Assert.Throws<PlatformNotSupportedException>(() => client.InBufferSize);
     }
 }
コード例 #59
0
        public static void ServerWriteOnlyThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws<NotSupportedException>(() => server.Read(new byte[5], 0, 5));

                Assert.Throws<NotSupportedException>(() => server.ReadByte());

                Assert.Throws<NotSupportedException>(() => server.InBufferSize);

                Assert.Throws<NotSupportedException>(() => NotReachable(server.ReadAsync(new byte[5], 0, 5)));
            }
        }
コード例 #60
0
        public static void ServerReadBufferNullThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                Assert.Throws<ArgumentNullException>(() => server.Read(null, 0, 1));

                Assert.Throws<ArgumentNullException>(() => NotReachable(server.ReadAsync(null, 0, 1)));
            }
        }