当前位置: 首页>>代码示例>>C#>>正文


C# Pipe.Read方法代码示例

本文整理汇总了C#中Pipe.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Pipe.Read方法的具体用法?C# Pipe.Read怎么用?C# Pipe.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pipe的用法示例。


在下文中一共展示了Pipe.Read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OneSideClose

        public void OneSideClose(string name)
        {
            int close_cb_called = 0;
            int cl_send_cb_called = 0;
            int cl_recv_cb_called = 0;
            int sv_send_cb_called = 0;
            int sv_recv_cb_called = 0;

            var server = new PipeListener();
            server.Bind(name);
            server.Connection += () => {
                var pipe = server.Accept();
                pipe.Resume();
                pipe.Read(Encoding.ASCII, (str) => {
                    sv_recv_cb_called++;
                    Assert.AreEqual("PING", str);
                    pipe.Write(Encoding.ASCII, "PONG", (s) => { sv_send_cb_called++; });
                    pipe.Close(() => { close_cb_called++; });
                    server.Close(() => { close_cb_called++; });
                });
            };
            server.Listen();

            Pipe client = new Pipe();
            client.Connect(name, (_) => {
                client.Read(Encoding.ASCII, (str) => {
                    cl_recv_cb_called++;
                    Assert.AreEqual("PONG", str);
                });

                client.Complete += () => {
                    close_cb_called++;
                };
                client.Resume();
                client.Write(Encoding.ASCII, "PING", (s) => { cl_send_cb_called++; });
            });

            Assert.AreEqual(0, close_cb_called);
            Assert.AreEqual(0, cl_send_cb_called);
            Assert.AreEqual(0, cl_recv_cb_called);
            Assert.AreEqual(0, sv_send_cb_called);
            Assert.AreEqual(0, sv_recv_cb_called);

            Loop.Default.Run();

            Assert.AreEqual(3, close_cb_called);
            Assert.AreEqual(1, cl_send_cb_called);
            Assert.AreEqual(1, cl_recv_cb_called);
            Assert.AreEqual(1, sv_send_cb_called);
            Assert.AreEqual(1, sv_recv_cb_called);

            #if DEBUG
            Assert.AreEqual(1, UV.PointerCount);
            #endif
        }
开发者ID:GamingAtheist,项目名称:LibuvSharp,代码行数:55,代码来源:PipeFixture.cs

示例2: ProcessSpawn

        Process ProcessSpawn(string command, Action<string> callback)
        {
            var stdout = new Pipe() { Writeable = true };

            var streams = new UVStream[] {
                null,
                stdout,
            };

            string text = null;

            var args = command.Split(new char[] { ' ' });
            var p = Process.Spawn(new ProcessOptions() {
                File = args[0],
                Arguments = args,
                Streams = streams
            }, (process) => {
                callback(text);
            });

            stdout.Read(Encoding.ASCII, (t) => text = t);
            stdout.Resume();
            return p;
        }
开发者ID:GamingAtheist,项目名称:LibuvSharp,代码行数:24,代码来源:ProcessFixture.cs

示例3: XReadActivated

        /// <summary>
        /// Indicate the given pipe as being ready for reading by this socket.
        /// </summary>
        /// <param name="pipe">the <c>Pipe</c> that is now becoming available for reading</param>
        protected override void XReadActivated(Pipe pipe)
        {
            // There are some subscriptions waiting. Let's process them.
            var sub = new Msg();
            var isBroadcast = false;
            while (pipe.Read(ref sub))
            {
                // Apply the subscription to the trie.
                int size = sub.Size;
                if (size > 0 && (sub[0] == 0 || sub[0] == 1) && !isBroadcast)
                {
                    if (m_manual)
                    {
                        m_pendingMessages.Enqueue(new KeyValuePair<Msg,Pipe>(sub, pipe));
                    }
                    else
                    {
                        var unique = sub[0] == 0
                            ? m_subscriptions.Remove(sub.Data, sub.Offset + 1, size - 1, pipe)
                            : m_subscriptions.Add(sub.Data, sub.Offset + 1, size - 1, pipe);

                        // If the subscription is not a duplicate, store it so that it can be
                        // passed to used on next recv call.
                        if (m_options.SocketType == ZmqSocketType.Xpub && (unique || m_verbose))
                        {
                            m_pendingMessages.Enqueue(new KeyValuePair<Msg, Pipe>(sub, null));
                        }
                        else
                        {
                            sub.Close();
                        }

                    }
                }
                else if (m_broadcastEnabled && size > 0 && sub[0] == 2)
                {
                    m_pendingMessages.Enqueue(new KeyValuePair<Msg, Pipe>(sub, pipe));
                    isBroadcast = true;
                }
                else // process message unrelated to sub/unsub
                {
                    // pipe is null here, no special treatment
                    m_pendingMessages.Enqueue(new KeyValuePair<Msg, Pipe>(sub, null));
                }

            }
        }
开发者ID:b-cuts,项目名称:netmq,代码行数:51,代码来源:XPub.cs

示例4: IdentifyPeer

        private bool IdentifyPeer( Pipe pipe)
        {
            byte[] identity;

            if (m_options.RawSocket)
            {
                // Always assign identity for raw-socket
                identity = new byte[5];
                byte[] result = BitConverter.GetBytes(m_nextPeerId++);
                Buffer.BlockCopy(result, 0, identity, 1, 4);
            }
            else
            {
                // Pick up handshake cases and also case where next identity is set

                var msg = new Msg();
                msg.InitEmpty();

                bool ok = pipe.Read(ref msg);

                if (!ok)
                    return false;

                if (msg.Size == 0)
                {
                    // Fall back on the auto-generation
                    identity = new byte[5];

                    byte[] result = BitConverter.GetBytes(m_nextPeerId++);

                    Buffer.BlockCopy(result, 0, identity, 1, 4);

                    msg.Close();
                }
                else
                {
                    identity = msg.CloneData();

                    // Ignore peers with duplicate ID.
                    if (m_outpipes.ContainsKey(identity))
                    {
                        msg.Close();
                        return false;
                    }

                    msg.Close();
                }
            }

            pipe.Identity = identity;
            // Add the record into output pipes lookup table
            var outpipe = new Outpipe(pipe, true);
            m_outpipes.Add(identity, outpipe);

            return true;
        }
开发者ID:awb99,项目名称:netmq,代码行数:56,代码来源:Router.cs

示例5: XReadActivated

        /// <summary>
        /// Indicate the given pipe as being ready for reading by this socket.
        /// </summary>
        /// <param name="pipe">the <c>Pipe</c> that is now becoming available for reading</param>
        protected override void XReadActivated(Pipe pipe)
        {
            // There are some subscriptions waiting. Let's process them.
            var sub = new Msg();
            while (pipe.Read(ref sub))
            {
                // Apply the subscription to the trie.
                byte[] data = sub.Data;
                int size = sub.Size;
                if (size > 0 && (data[0] == 0 || data[0] == 1))
                {
                    if (m_manual)
                    {
                        m_lastPipe = pipe;

                        m_pending.Enqueue(sub.CloneData());
                    }
                    else
                    {
                        var unique = data[0] == 0
                            ? m_subscriptions.Remove(data, 1, size - 1, pipe)
                            : m_subscriptions.Add(data, 1, size - 1, pipe);

                        // If the subscription is not a duplicate, store it so that it can be
                        // passed to used on next recv call.
                        if (m_options.SocketType == ZmqSocketType.Xpub && (unique || m_verbose))
                            m_pending.Enqueue(sub.CloneData());
                    }
                }
                else // process message unrelated to sub/unsub
                {
                    m_pending.Enqueue(sub.CloneData());
                }

                sub.Close();
            }
        }
开发者ID:wangkai2014,项目名称:netmq,代码行数:41,代码来源:XPub.cs

示例6: Stress

        public void Stress(string name)
        {
            for (int j = 0; j < 10; j++) {
                int times = 10;

                int close_cb_called = 0;
                int cl_send_cb_called = 0;
                int cl_recv_cb_called = 0;
                int sv_send_cb_called = 0;
                int sv_recv_cb_called = 0;

                var server = new PipeListener();
                server.Bind(name);
                server.Connection += () => {
                    var pipe = server.Accept();
                    pipe.Resume();
                    pipe.Read(Encoding.ASCII, (str) => {
                        sv_recv_cb_called++;
                        Assert.AreEqual(Times("PING", times), str);
                        for (int i = 0; i < times; i++) {
                            pipe.Write(Encoding.ASCII, "PONG", (s) => { sv_send_cb_called++; });
                        }
                        pipe.Close(() => { close_cb_called++; });
                        server.Close(() => { close_cb_called++; });
                    });
                };
                server.Listen();

                Pipe client = new Pipe();
                client.Connect(name, (_) => {
                    client.Resume();
                    for (int i = 0; i < times; i++) {
                        client.Write(Encoding.ASCII, "PING", (s) => { cl_send_cb_called++; });
                    }
                    client.Read(Encoding.ASCII, (str) => {
                        cl_recv_cb_called++;
                        Assert.AreEqual(Times("PONG", times), str);
                        client.Close(() => { close_cb_called++; });
                    });
                });

                Assert.AreEqual(0, close_cb_called);
                Assert.AreEqual(0, cl_send_cb_called);
                Assert.AreEqual(0, cl_recv_cb_called);
                Assert.AreEqual(0, sv_send_cb_called);
                Assert.AreEqual(0, sv_recv_cb_called);

                Loop.Default.Run();

                Assert.AreEqual(3, close_cb_called);
                Assert.AreEqual(times, cl_send_cb_called);
                Assert.AreEqual(1, cl_recv_cb_called);
                Assert.AreEqual(times, sv_send_cb_called);
                Assert.AreEqual(1, sv_recv_cb_called);

            #if DEBUG
                Assert.AreEqual(1, UV.PointerCount);
            #endif
            }
        }
开发者ID:GamingAtheist,项目名称:LibuvSharp,代码行数:60,代码来源:PipeFixture.cs


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