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


C# Msg.Close方法代码示例

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


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

示例1: CopyPooled

        public void CopyPooled()
        {
            var pool = new MockBufferPool();
            BufferPool.SetCustomBufferPool(pool);

            var msg = new Msg();
            msg.InitPool(100);

            Assert.IsFalse(msg.IsShared);

            var copy = new Msg();
            copy.Copy(ref msg);

            Assert.IsTrue(msg.IsShared);
            Assert.IsTrue(copy.IsShared);

            msg.Close();

            Assert.AreEqual(0, pool.ReturnCallCount);
            Assert.IsFalse(msg.IsInitialised);
            Assert.IsNull(msg.Data);

            copy.Close();

            Assert.AreEqual(1, pool.ReturnCallCount);
            Assert.IsFalse(copy.IsInitialised);
            Assert.IsNull(copy.Data);
        }
开发者ID:wangkai2014,项目名称:netmq,代码行数:28,代码来源:MsgTests.cs

示例2: Main

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

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

            using (var context = NetMQContext.Create())
            using (var push = context.CreatePushSocket())
            {
                push.Connect(connectTo);

                for (int i = 0; i != messageCount; i++)
                {
                    var message = new Msg();
                    message.InitPool(messageSize);
                    push.Send(ref message, SendReceiveOptions.None);
                    message.Close();
                }
            }

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

示例3: XSetSocketOption

        /// <summary>
        /// Set the specified option on this socket - which must be either a SubScribe or an Unsubscribe.
        /// </summary>
        /// <param name="option">which option to set</param>
        /// <param name="optionValue">the value to set the option to</param>
        /// <returns><c>true</c> if successful</returns>
        /// <exception cref="InvalidException">optionValue must be a String or a byte-array.</exception>
        protected override bool XSetSocketOption(ZmqSocketOption option, object optionValue)
        {
            // Only subscribe/unsubscribe options are supported
            if (option != ZmqSocketOption.Subscribe && option != ZmqSocketOption.Unsubscribe)
                return false;

            byte[] topic;
            if (optionValue is string)
                topic = Encoding.ASCII.GetBytes((string)optionValue);
            else if (optionValue is byte[])
                topic = (byte[])optionValue;
            else
                throw new InvalidException($"In Sub.XSetSocketOption({option},{optionValue?.ToString() ?? "null"}), optionValue must be either a string or a byte-array.");

            // Create the subscription message.
            var msg = new Msg();
            msg.InitPool(topic.Length + 1);
            msg.Put(option == ZmqSocketOption.Subscribe ? (byte)1 : (byte)0);
            msg.Put(topic, 1, topic.Length);

            try
            {
                // Pass it further on in the stack.
                var isMessageSent = base.XSend(ref msg);

                if (!isMessageSent)
                    throw new Exception($"in Sub.XSetSocketOption({option}, {optionValue}), XSend returned false.");
            }
            finally
            {
                msg.Close();
            }

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

示例4: Send

        /// <summary>
        /// Transmit a byte-array of data over this socket.
        /// </summary>
        /// <param name="socket">the IOutgoingSocket to transmit on</param>
        /// <param name="data">the byte-array of data to send</param>
        /// <param name="length">the number of bytes to send from <paramref name="data"/>.</param>
        /// <param name="options">options to control how the data is sent</param>
        public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data, int length, SendReceiveOptions options)
        {
            var msg = new Msg();
            msg.InitPool(length);

            Buffer.BlockCopy(data, 0, msg.Data, 0, length);

            socket.Send(ref msg, options);

            msg.Close();
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:18,代码来源:OutgoingSocketExtensions.cs

示例5: Receive

        public static byte[] Receive([NotNull] this IReceivingSocket socket, SendReceiveOptions options, out bool hasMore)
        {
            var msg = new Msg();
            msg.InitEmpty();

            socket.Receive(ref msg, options);

            var data = msg.CloneData();

            hasMore = msg.HasMore;

            msg.Close();

            return data;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:15,代码来源:ReceivingSocketExtensions.cs

示例6: ForwardTo

        private static void ForwardTo(NetMQSocketEventArgs args, IOutgoingSocket toSocket)
        {
            var msg = new Msg();
            msg.InitEmpty();

            bool more;
            do
            {
                args.Socket.Receive(ref msg);
                more = msg.HasMore;
                toSocket.Send(ref msg, more);
            }
            while (more);

            msg.Close();
        }
开发者ID:romanros,项目名称:netmq,代码行数:16,代码来源:QueueDevice.cs

示例7: Plug

        public void Plug(IOThread ioThread, SessionBase session)
        {
            m_encoder.SetMsgSource(session);

            // get the first message from the session because we don't want to send identities
            var msg = new Msg();
            msg.InitEmpty();

            bool ok = session.PullMsg(ref msg);

            if (ok)
            {
                msg.Close();
            }

            AddSocket(m_socket);

            m_state = State.Connecting;
            m_socket.Connect(m_pgmAddress.Address);
        }
开发者ID:awb99,项目名称:netmq,代码行数:20,代码来源:PgmSender.cs

示例8: ProcessPipeTermAck

        /// <summary>
        /// Process the pipe-termination ack.
        /// </summary>
        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.TryRead(out msg))
            {
                msg.Close();
            }

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

示例9: ProcessHiccup

        /// <summary>
        /// This method is called to assign the specified pipe as a replacement for the outbound pipe that was being used.
        /// </summary>
        /// <param name="pipe">the pipe to use for writing</param>
        /// <remarks>
        /// A "Hiccup" occurs when an outbound pipe experiences something like a transient disconnect or for whatever other reason
        /// is no longer available for writing to.
        /// </remarks>
        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.TryRead(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:vordoom,项目名称:netmq,代码行数:29,代码来源:Pipe.cs

示例10: 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:vordoom,项目名称:netmq,代码行数:16,代码来源:Pipe.cs

示例11: Distribute

        /// <summary>
        /// Put the message to all active pipes.
        /// </summary>
        private void Distribute(ref Msg msg)
        {
            //  If there are no matching pipes available, simply drop the message.
            if (m_matching == 0)
            {
                msg.Close();
                msg.InitEmpty();

                return;
            }

            if (msg.MsgType != MsgType.Pool)
            {
                for (int i = 0; i < m_matching; ++i)
                {
                    if (!Write(m_pipes[i], ref msg))
                    {
                        --i; //  Retry last write because index will have been swapped
                    }
                }

                msg.Close();
                msg.InitEmpty();

                return;
            }

            //  Add matching-1 references to the message. We already hold one reference,
            //  that's why -1.
            msg.AddReferences(m_matching - 1);

            //  Push copy of the message to each matching pipe.
            int failed = 0;
            for (int i = 0; i < m_matching; ++i)
            {
                if (!Write(m_pipes[i], ref msg))
                {
                    ++failed;
                    --i; //  Retry last write because index will have been swapped
                }
            }
            if (failed != 0)
                msg.RemoveReferences(failed);

            //  Detach the original message from the data buffer. Note that we don't
            //  close the message. That's because we've already used all the references.
            msg.InitEmpty();
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:51,代码来源:Distribution.cs

示例12: RecvPipe

        public bool RecvPipe(Pipe[] pipe, ref Msg msg)
        {
            //  Deallocate old content of the message.
            msg.Close();

            //  Round-robin over the pipes to get the next message.
            while (m_active > 0)
            {

                //  Try to fetch new message. If we've already read part of the message
                //  subsequent part should be immediately available.
                bool fetched = m_pipes[m_current].Read(ref msg);

                //  Note that when message is not fetched, current pipe is deactivated
                //  and replaced by another active pipe. Thus we don't have to increase
                //  the 'current' pointer.
                if (fetched)
                {
                    if (pipe != null)
                        pipe[0] = m_pipes[m_current];
                    m_more = msg.HasMore;
                    if (!m_more)
                        m_current = (m_current + 1) % m_active;
                    return true;
                }

                //  Check the atomicity of the message.
                //  If we've already received the first part of the message
                //  we should get the remaining parts without blocking.
                Debug.Assert(!m_more);

                m_active--;
                m_pipes.Swap(m_current, m_active);
                if (m_current == m_active)
                    m_current = 0;
            }

            //  No message is available. Initialise the output parameter
            //  to be a 0-byte message.
            msg.InitEmpty();
            return false;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:42,代码来源:FairQueueing.cs

示例13: Send

        public bool Send(ref Msg msg)
        {
            // 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();
                msg.InitEmpty();
                return true;
            }

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

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

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

            // If it's part of the message we can flush 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;
            }

            // Detach the message from the data buffer.
            msg.InitEmpty();

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

示例14: XSend

        /// <summary>
        /// Transmit the given message. The <c>Send</c> method calls this to do the actual sending.
        /// </summary>
        /// <param name="msg">the message to transmit</param>
        /// <returns><c>true</c> if the message was sent successfully</returns>
        /// <exception cref="HostUnreachableException">The receiving host must be identifiable.</exception>
        protected override bool XSend(ref Msg msg)
        {
            // If this is the first part of the message it's the ID of the
            // peer to send the message to.
            if (!m_moreOut)
            {
                Debug.Assert(m_currentOut == null);

                // If we have malformed message (prefix with no subsequent message)
                // then just silently ignore it.
                // TODO: The connections should be killed instead.
                if (msg.HasMore)
                {
                    m_moreOut = true;

                    // Find the pipe associated with the identity stored in the prefix.
                    // If there's no such pipe just silently ignore the message, unless
                    // mandatory is set.

                    var identity = msg.Size == msg.Data.Length 
                        ? msg.Data
                        : msg.CloneData();

                    Outpipe op;

                    if (m_outpipes.TryGetValue(identity, out op))
                    {
                        m_currentOut = op.Pipe;
                        if (!m_currentOut.CheckWrite())
                        {
                            op.Active = false;
                            m_currentOut = null;
                            if (m_mandatory)
                            {
                                m_moreOut = false;
                                return false;
                            }
                        }
                    }
                    else if (m_mandatory)
                    {
                        m_moreOut = false;
                        throw new HostUnreachableException("In Router.XSend");
                    }
                }

                // Detach the message from the data buffer.
                msg.Close();
                msg.InitEmpty();

                return true;
            }

            if (m_options.RawSocket)
            {
                msg.ResetFlags(MsgFlags.More);
            }

            // Check whether this is the last part of the message.
            m_moreOut = msg.HasMore;

            // Push the message into the pipe. If there's no out pipe, just drop it.
            if (m_currentOut != null)
            {
                // Close the remote connection if user has asked to do so
                // by sending zero length message.
                // Pending messages in the pipe will be dropped (on receiving term-ack)
                if (m_rawSocket && msg.Size == 0)
                {
                    m_currentOut.Terminate(false);
                    msg.Close();
                    msg.InitEmpty();
                    m_currentOut = null;
                    return true;
                }

                bool ok = m_currentOut.Write(ref msg);
                if (!ok)
                    m_currentOut = null;
                else if (!m_moreOut)
                {
                    m_currentOut.Flush();
                    m_currentOut = null;
                }
            }
            else
            {
                msg.Close();
            }

            // Detach the message from the data buffer.            
            msg.InitEmpty();

            return true;
//.........这里部分代码省略.........
开发者ID:awb99,项目名称:netmq,代码行数:101,代码来源:Router.cs

示例15: ProxyBetween

        private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
        {
            var msg = new Msg();
            msg.InitEmpty();

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

            while (true)
            {
                from.Receive(ref msg, SendReceiveOptions.None);
                bool more = from.Options.ReceiveMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
                }

                to.Send(ref msg, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);

                if (!more)
                {
                    break;
                }
            }

            copy.Close();
            msg.Close();
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:31,代码来源:Proxy.cs


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