public static void ServerSendsByteClientReceives()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            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);
                int bytesReceived = client.Read(received, 0, 1);
                Assert.Equal(1, bytesReceived);
                Assert.Equal(sent[0], received[0]);
            }
        }
    }
Exemplo n.º 2
0
    public static void ServerSendsByteClientReceives()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            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));
        }
    }
Exemplo n.º 3
0
        static void Main( string[] args )
        {
            #if DEBUG
            Console.WriteLine("PID {0} Debug", Process.GetCurrentProcess().Id );
            #else
            Console.WriteLine("PID {0} Release", Process.GetCurrentProcess().Id );
            #endif
            if (!args.Any(arg=>arg.StartsWith("--original="))) { // Assume we're the original process
                OriginalPath = Assembly.GetExecutingAssembly().GetName().CodeBase;
                // Relaunch and quit so that we don't lock the original executable:
                Relaunch();
                return;
            }

            OriginalPath = args.First(arg=>arg.StartsWith("--original=")).Remove(0,"--original=".Length);
            if (args.Any(arg=>arg.StartsWith("--pipe="))) {
                var pipename = args.First(arg=>arg.StartsWith("--pipe=")).Remove(0,"--pipe=".Length);
                var pipe   = new AnonymousPipeClientStream(pipename);
                var buffer = new byte[9001];

                int read=0, length=0;
                do {
                    read = pipe.Read(buffer,length,buffer.Length-length);
                    length += read;
                } while ( read!=0 );

                var si = new SocketInformation()
                    { Options = SocketInformationOptions.Connected | SocketInformationOptions.UseOnlyOverlappedIO
                    , ProtocolInformation = buffer.Take(length).ToArray()
                    };
                Connection = IrcConnection.RecoverConnectionFrom( new Socket(si) );
            } else {
                Connection = new IrcConnection( "irc.afternet.org", 6667 );
            }

            Connection.Listeners.Add(new CommandResponder(){State=Connection.Listeners[0] as IrcConnectionState});
            Connection.BeginPumping();
            Connection.WaitPumping();
            if ( RelaunchFlag ) Relaunch();
        }
Exemplo n.º 4
0
    public static void ClientPInvokeChecks()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
        {
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
            {
                Task serverTask = Task.Run(() => DoStreamOperations(server));

                Assert.False(client.CanRead);
                Assert.False(client.CanSeek);
                Assert.False(client.CanTimeout);
                Assert.True(client.CanWrite);
                Assert.False(client.IsAsync);
                Assert.True(client.IsConnected);
                if (Interop.IsWindows)
                {
                    Assert.Equal(0, client.OutBufferSize);
                }
                else
                {
                    Assert.Throws<PlatformNotSupportedException>(() => client.OutBufferSize);
                }
                Assert.Equal(PipeTransmissionMode.Byte, client.ReadMode);
                Assert.NotNull(client.SafePipeHandle);
                Assert.Equal(PipeTransmissionMode.Byte, client.TransmissionMode);

                client.Write(new byte[] { 123 }, 0, 1);
                client.WriteAsync(new byte[] { 124 }, 0, 1).Wait();
                if (Interop.IsWindows)
                {
                    client.WaitForPipeDrain();
                }
                else
                {
                    Assert.Throws<PlatformNotSupportedException>(() => client.WaitForPipeDrain());
                }
                client.Flush();

                serverTask.Wait();
            }
        }

        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
            {
                Task serverTask = Task.Run(() => DoStreamOperations(server));

                if (Interop.IsWindows)
                {
                    Assert.Equal(4096, client.InBufferSize);
                }
                else
                {
                    Assert.Throws<PlatformNotSupportedException>(() => client.InBufferSize);
                }
                byte[] readData = new byte[] { 0, 1 };
                Assert.Equal(1, client.Read(readData, 0, 1));
                Assert.Equal(1, client.ReadAsync(readData, 1, 1).Result);
                Assert.Equal(123, readData[0]);
                Assert.Equal(124, readData[1]);

                serverTask.Wait();
            }
        }
    }
    public static void ClientPInvokeChecks()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
        {
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.Out, server.ClientSafePipeHandle))
            {
                Task serverTask = DoServerOperationsAsync(server);
                Console.WriteLine("client.CanRead = {0}", client.CanRead);
                Console.WriteLine("client.CanSeek = {0}", client.CanSeek);
                Console.WriteLine("client.CanTimeout = {0}", client.CanTimeout);
                Console.WriteLine("client.CanWrite = {0}", client.CanWrite);
                Console.WriteLine("client.IsAsync = {0}", client.IsAsync);
                Console.WriteLine("client.IsConnected = {0}", client.IsConnected);
                Console.WriteLine("client.OutBufferSize = {0}", client.OutBufferSize);
                Console.WriteLine("client.ReadMode = {0}", client.ReadMode);
                Console.WriteLine("client.SafePipeHandle = {0}", client.SafePipeHandle);
                Console.WriteLine("client.TransmissionMode = {0}", client.TransmissionMode);

                client.Write(new byte[] { 123 }, 0, 1);
                client.WriteAsync(new byte[] { 124 }, 0, 1).Wait();
                client.WaitForPipeDrain();
                client.Flush();

                serverTask.Wait();
            }
        }

        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle))
            {
                Task serverTask = DoServerOperationsAsync(server);

                Console.WriteLine("client.InBufferSize = {0}", client.InBufferSize);
                byte[] readData = new byte[] { 0, 1 };
                client.Read(readData, 0, 1);
                client.ReadAsync(readData, 1, 1).Wait();
                Assert.Equal(123, readData[0]);
                Assert.Equal(124, readData[1]);

                serverTask.Wait();
            }
        }
    }