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


C# Msg.Close方法代码示例

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


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

示例1: Main

        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: remote_lat remote_lat <connect-to> <message-size> <roundtrip-count>");
                return 1;
            }

            string connectTo = args[0];
            int messageSize = int.Parse(args[1]);
            int roundtripCount = int.Parse(args[2]);

            var context = ZMQ.CtxNew();
            var reqSocket = ZMQ.Socket(context, ZmqSocketType.Req);
            bool connected = reqSocket.Connect(connectTo);
            if (!connected)
            {
                Console.WriteLine("error in zmq_connect");
            }

            var message = new Msg(messageSize);

            var stopWatch = Stopwatch.StartNew();

            for (int i = 0; i != roundtripCount; i++)
            {
                bool sent = reqSocket.Send(message, SendRecieveOptions.None);
                if (!sent)
                {
                    Console.WriteLine("error in zmq_sendmsg");
                    return -1;
                }

                message = reqSocket.Recv(SendRecieveOptions.None);
                if (message.Size != messageSize)
                {
                    Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
                    return -1;
                }
            }

            stopWatch.Stop();

            message.Close();

            double elapsedMicroseconds = stopWatch.ElapsedTicks * 1000000 / Stopwatch.Frequency;
            double latency = elapsedMicroseconds / (roundtripCount * 2);

            Console.WriteLine("message size: {0} [B]", messageSize);
            Console.WriteLine("roundtrip count: {0}", roundtripCount);
            Console.WriteLine("average latency: {0:0.000} [µs]", latency);

            reqSocket.Close();
            context.Terminate();

            return 0;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:57,代码来源:Program.cs

示例2: XSub

        static XSub()
        {
            s_sendSubscription = (data, size, arg) => {

                                                       	Pipe pipe = (Pipe) arg;

                                                       	//  Create the subsctription message.
                                                       	Msg msg = new Msg(size + 1);
                                                       	msg.Put((byte)1);
                                                       	msg.Put(data,1, size);

                                                       	//  Send it to the pipe.
                                                       	bool sent = pipe.Write (msg);
                                                       	//  If we reached the SNDHWM, and thus cannot send the subscription, drop
                                                       	//  the subscription message instead. This matches the behaviour of
                                                       	//  zmq_setsockopt(ZMQ_SUBSCRIBE, ...), which also drops subscriptions
                                                       	//  when the SNDHWM is reached.
                                                       	if (!sent)
                                                       		msg.Close ();

            };
        }
开发者ID:jasenkin,项目名称:netmq,代码行数:22,代码来源:XSub.cs

示例3: Send

        public bool Send(Msg msg, SendRecieveOptions flags)
        {
            //  Drop the message if required. If we are at the end of the message
            //  switch back to non-dropping mode.
            if (m_dropping) {

                m_more = msg.HasMore;
                m_dropping = m_more;

                msg.Close ();
                return true;
            }

            while (m_active > 0) {
                if (m_pipes[m_current].Write (msg))
                    break;

                Debug.Assert(!m_more);
                m_active--;
                if (m_current < m_active)
                    Utils.Swap (m_pipes, m_current, m_active);
                else
                    m_current = 0;
            }

            //  If there are no pipes we cannot send the message.
            if (m_active == 0) {
                ZError.ErrorNumber = ErrorNumber.EAGAIN;
                return false;
            }

            //  If it's part of the message we can fluch it downstream and
            //  continue round-robinning (load balance).
            m_more = msg.HasMore;
            if (!m_more) {
                m_pipes[m_current].Flush();
                if (m_active > 1)
                    m_current = (m_current + 1) % m_active;
            }

            return true;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:42,代码来源:LB.cs

示例4: ProcessPipeTermAck

        protected override void ProcessPipeTermAck()
        {
            //  Notify the user that all the references to the pipe should be dropped.
            Debug.Assert(m_sink != null);
            m_sink.Terminated(this);

            //  In terminating and double_terminated states there's nothing to do.
            //  Simply deallocate the pipe. In terminated state we have to ack the
            //  peer before deallocating this side of the pipe. All the other states
            //  are invalid.
            if (m_state == State.Terminated)
            {
                m_outboundPipe = null;
                SendPipeTermAck(m_peer);
            }
            else
                Debug.Assert(m_state == State.Terminating || m_state == State.DoubleTerminated);

            //  We'll deallocate the inbound pipe, the peer will deallocate the outbound
            //  pipe (which is an inbound pipe from its point of view).
            //  First, delete all the unread messages in the pipe. We have to do it by
            //  hand because msg_t doesn't have automatic destructor. Then deallocate
            //  the ypipe itself.
            var msg = new Msg();
            while (m_inboundPipe.Read(out msg))
            {
                msg.Close();
            }

            m_inboundPipe = null;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:31,代码来源:Pipe.cs

示例5: ProcessHiccup

        protected override void ProcessHiccup(object pipe)
        {
            //  Destroy old out-pipe. Note that the read end of the pipe was already
            //  migrated to this thread.
            Debug.Assert(m_outboundPipe != null);
            m_outboundPipe.Flush();
            var msg = new Msg();
            while (m_outboundPipe.Read(out msg))
            {
                msg.Close();
            }

            //  Plug in the new out-pipe.
            Debug.Assert(pipe != null);
            m_outboundPipe = (YPipe<Msg>)pipe;
            m_outActive = true;

            //  If appropriate, notify the user about the hiccup.
            if (m_state == State.Active)
                m_sink.Hiccuped(this);
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:21,代码来源:Pipe.cs

示例6: Rollback

 /// <summary>
 /// Remove unfinished parts of the outbound message from the pipe.
 /// </summary>
 public void Rollback()
 {
     //  Remove incomplete message from the outbound pipe.
     if (m_outboundPipe != null)
     {
         var msg = new Msg();
         while (m_outboundPipe.Unwrite(ref msg))
         {
             Debug.Assert(msg.HasMore);
             msg.Close();
         }
     }
 }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:16,代码来源:Pipe.cs

示例7: CleanPipes

        //  Remove any half processed messages. Flush unflushed messages.
        //  Call this function when engine disconnect to get rid of leftovers.
        private void CleanPipes()
        {
            if (m_pipe != null)
            {
                //  Get rid of half-processed messages in the out pipe. Flush any
                //  unflushed messages upstream.
                m_pipe.Rollback();
                m_pipe.Flush();

                //  Remove any half-read message from the in pipe.
                while (m_incompleteIn)
                {
                    var msg = new Msg();
                    msg.InitEmpty();

                    if (!PullMsg(ref msg))
                    {
                        Debug.Assert(!m_incompleteIn);
                        break;
                    }
                    msg.Close();
                }
            }
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:26,代码来源:SessionBase.cs

示例8: PushMsg

        public virtual bool PushMsg(ref Msg msg)
        {
            //  First message to receive is identity (if required).
            if (!m_identityReceived)
            {
                msg.SetFlags(MsgFlags.Identity);
                m_identityReceived = true;

                if (!m_options.RecvIdentity)
                {
                    msg.Close();
                    msg.InitEmpty();
                    return true;
                }
            }

            if (m_pipe != null && m_pipe.Write(ref msg))
            {
                msg.InitEmpty();
                return true;
            }

            return false;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:24,代码来源:SessionBase.cs


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