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


C# Msg.Put方法代码示例

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


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

示例1: 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

示例2: XSetSocketOption

        protected override bool XSetSocketOption(ZmqSocketOptions option, Object optionValue)
        {
            if (option != ZmqSocketOptions.Subscribe && option != ZmqSocketOptions.Unsubscribe)
            {
                return false;
            }

            byte[] val;

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

            //  Create the subscription message.
            var msg = new Msg();
            msg.InitPool(val.Length + 1);
            if (option == ZmqSocketOptions.Subscribe)
                msg.Put(1);
            else if (option == ZmqSocketOptions.Unsubscribe)
                msg.Put(0);
            msg.Put(val, 1, val.Length);

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

                if (!isMessageSent)
                {
                    string xMsg = string.Format("in Sub.XSetSocketOption({0}, {1}), XSend returned false.", option, optionValue);
                    throw new AgainException(innerException: null, message: xMsg);
                }
            }
            finally
            {
                msg.Close();
            }

            return true;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:43,代码来源:Sub.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>
        /// <exception cref="AgainException">XSend must return true.</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(string.Format("In Sub.XSetSocketOption({0},{1}), optionValue must be either a string or a byte-array.", option, (optionValue == null ? "null" : optionValue.ToString())));

            // 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.
                bool isMessageSent = base.XSend(ref msg);

                if (!isMessageSent)
                {
                    string xMsg = string.Format("in Sub.XSetSocketOption({0}, {1}), XSend returned false.", option, optionValue);
                    // TODO: should we change the exception that is thrown here as AgainException is obsolete?
#pragma warning disable 618                    
                    throw new AgainException(innerException: null, message: xMsg);
#pragma warning restore 618
                }
            }
            finally
            {
                msg.Close();
            }

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

示例4: XSub

        static XSub()
        {
            s_sendSubscription = (data, size, arg) =>
            {
                var pipe = (Pipe)arg;

                // Create the subscription message.
                var msg = new Msg();
                msg.InitPool(size + 1);
                msg.Put(1);
                msg.Put(data, 1, size);

                // Send it to the pipe.
                bool sent = pipe.Write(ref 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:wangkai2014,项目名称:netmq,代码行数:22,代码来源:XSub.cs

示例5: XPub

        static XPub()
        {
            s_markAsMatching = (pipe, data, size, arg) =>
            {
                var self = (XPub)arg;
                // skip the sender of a broadcast message
                if (!(self.m_broadcastEnabled && self.m_lastPipeIsBroadcast && self.m_lastPipe == pipe))
                {
                    self.m_distribution.Match(pipe);
                }
            };

            s_sendUnsubscription = (pipe, data, size, arg) =>
            {
                var self = (XPub)arg;

                if (self.m_options.SocketType != ZmqSocketType.Pub)
                {
                    // Place the unsubscription to the queue of pending (un)subscriptions
                    // to be retrieved by the user later on.

                    var unsubMsg = new Msg();
                    unsubMsg.InitPool(size + 1);
                    unsubMsg[0] = 0;
                    unsubMsg.Put(data, 1, size);

                    self.m_pendingMessages.Enqueue(new KeyValuePair<Msg, Pipe>(unsubMsg, pipe));
                }
            };
        }
开发者ID:b-cuts,项目名称:netmq,代码行数:30,代码来源:XPub.cs

示例6: Connect

        /// <summary>
        /// Connect this socket to the given address.
        /// </summary>
        /// <param name="addr">a string denoting the endpoint to connect to</param>
        /// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
        /// <exception cref="NetMQException">No IO thread was found.</exception>
        /// <exception cref="ProtocolNotSupportedException">the specified protocol is not supported</exception>
        /// <exception cref="ProtocolNotSupportedException">the socket type and protocol do not match</exception>
        /// <exception cref="TerminatingException">The socket has been stopped.</exception>
        /// <remarks>
        /// The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm".
        /// If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub.
        /// </remarks>
        /// <exception cref="EndpointNotFoundException">The given address was not found in the list of endpoints.</exception>
        public void Connect([NotNull] string addr)
        {
            CheckContextTerminated();

            // Process pending commands, if any.
            ProcessCommands(0, false);

            string address;
            string protocol;
            DecodeAddress(addr, out address, out protocol);

            CheckProtocol(protocol);

            if (protocol == Address.InProcProtocol)
            {
                // TODO: inproc connect is specific with respect to creating pipes
                // as there's no 'reconnect' functionality implemented. Once that
                // is in place we should follow generic pipe creation algorithm.

                // Find the peer endpoint.
                Ctx.Endpoint peer = FindEndpoint(addr);

                // The total HWM for an inproc connection should be the sum of
                // the binder's HWM and the connector's HWM.
                var sndhwm = m_options.SendHighWatermark != 0 && peer.Options.ReceiveHighWatermark != 0
                    ? m_options.SendHighWatermark + peer.Options.ReceiveHighWatermark
                    : 0;

                var rcvhwm = m_options.ReceiveHighWatermark != 0 && peer.Options.SendHighWatermark != 0
                    ? m_options.ReceiveHighWatermark + peer.Options.SendHighWatermark
                    : 0;

                // The total LWM for an inproc connection should be the sum of
                // the binder's LWM and the connector's LWM.
                int sndlwm = m_options.SendLowWatermark != 0 && peer.Options.ReceiveLowWatermark != 0
                    ? m_options.SendLowWatermark + peer.Options.ReceiveLowWatermark
                    : 0;

                int rcvlwm = m_options.ReceiveLowWatermark != 0 && peer.Options.SendLowWatermark != 0
                    ? m_options.ReceiveLowWatermark + peer.Options.SendLowWatermark
                    : 0;

                // Create a bi-directional pipe to connect the peers.
                ZObject[] parents = { this, peer.Socket };
                int[] highWaterMarks = { sndhwm, rcvhwm };
                int[] lowWaterMarks = { sndlwm, rcvlwm };
                bool[] delays = { m_options.DelayOnDisconnect, m_options.DelayOnClose };
                Pipe[] pipes = Pipe.PipePair(parents, highWaterMarks, lowWaterMarks, delays);

                // Attach local end of the pipe to this socket object.
                AttachPipe(pipes[0]);

                // If required, send the identity of the local socket to the peer.
                if (peer.Options.RecvIdentity)
                {
                    var id = new Msg();
                    id.InitPool(m_options.IdentitySize);
                    id.Put(m_options.Identity, 0, m_options.IdentitySize);
                    id.SetFlags(MsgFlags.Identity);
                    bool written = pipes[0].Write(ref id);
                    Debug.Assert(written);
                    pipes[0].Flush();
                }

                // If required, send the identity of the peer to the local socket.
                if (m_options.RecvIdentity)
                {
                    var id = new Msg();
                    id.InitPool(peer.Options.IdentitySize);
                    id.Put(peer.Options.Identity, 0, peer.Options.IdentitySize);
                    id.SetFlags(MsgFlags.Identity);
                    bool written = pipes[1].Write(ref id);
                    Debug.Assert(written);
                    pipes[1].Flush();
                }

                // Attach remote end of the pipe to the peer socket. Note that peer's
                // seqnum was incremented in find_endpoint function. We don't need it
                // increased here.
                SendBind(peer.Socket, pipes[1], false);

                // Save last endpoint URI
                m_options.LastEndpoint = addr;

                // remember inproc connections for disconnect
                m_inprocs.Add(addr, pipes[0]);
//.........这里部分代码省略.........
开发者ID:GrabCAD,项目名称:netmq,代码行数:101,代码来源:SocketBase.cs

示例7: PullMsg

        /// <summary>
        /// Read a message from the pipe.
        /// </summary>
        /// <param name="msg">a reference to a Msg to put the message into</param>
        /// <returns>true if the Msg is successfully sent</returns>
        public virtual bool PullMsg(ref Msg msg)
        {
            // First message to send is identity
            if (!m_identitySent)
            {
                msg.InitPool(m_options.IdentitySize);
                msg.Put(m_options.Identity, 0, m_options.IdentitySize);
                m_identitySent = true;
                m_incompleteIn = false;

                return true;
            }

            if (m_pipe == null || !m_pipe.Read(ref msg))
            {
                return false;
            }
            m_incompleteIn = msg.HasMore;

            return true;
        }
开发者ID:sharpe5,项目名称:netmq,代码行数:26,代码来源:SessionBase.cs

示例8: XHasIn

        protected override bool XHasIn()
        {
            // If we are in the middle of reading the messages, there are
            // definitely more parts available.
            if (m_moreIn)
                return true;

            // We may already have a message pre-fetched.
            if (m_prefetched)
                return true;

            // Try to read the next message.
            // The message, if read, is kept in the pre-fetch buffer.
            var pipe = new Pipe[1];

            bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);

            // It's possible that we receive peer's identity. That happens
            // after reconnection. The current implementation assumes that
            // the peer always uses the same identity.
            // TODO: handle the situation when the peer changes its identity.
            while (isMessageAvailable && m_prefetchedMsg.IsIdentity)
            {
                isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);
            }

            if (!isMessageAvailable)
                return false;

            Debug.Assert(pipe[0] != null);

            byte[] identity = pipe[0].Identity;
            m_prefetchedId = new Msg();
            m_prefetchedId.InitPool(identity.Length);
            m_prefetchedId.Put(identity, 0, identity.Length);
            m_prefetchedId.SetFlags(MsgFlags.More);

            m_prefetched = true;
            m_identitySent = false;

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

示例9: XRecv

        /// <summary>
        /// Receive a message. The <c>Recv</c> method calls this lower-level method to do the actual receiving.
        /// </summary>
        /// <param name="msg">the <c>Msg</c> to receive the message into</param>
        /// <returns><c>true</c> if the message was received successfully, <c>false</c> if there were no messages to receive</returns>
        protected override bool XRecv(ref Msg msg)
        {
            if (m_prefetched)
            {
                if (!m_identitySent)
                {
                    msg.Move(ref m_prefetchedId);
                    m_identitySent = true;
                }
                else
                {
                    msg.Move(ref m_prefetchedMsg);
                    m_prefetched = false;
                }
                m_moreIn = msg.HasMore;
                return true;
            }

            var pipe = new Pipe[1];

            bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref msg);

            // It's possible that we receive peer's identity. That happens
            // after reconnection. The current implementation assumes that
            // the peer always uses the same identity.            
            while (isMessageAvailable && msg.IsIdentity)
                isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref msg);

            if (!isMessageAvailable)
            {
                return false;
            }

            Debug.Assert(pipe[0] != null);

            // If we are in the middle of reading a message, just return the next part.
            if (m_moreIn)
                m_moreIn = msg.HasMore;
            else
            {
                // We are at the beginning of a message.
                // Keep the message part we have in the prefetch buffer
                // and return the ID of the peer instead.
                m_prefetchedMsg.Move(ref msg);

                m_prefetched = true;

                byte[] identity = pipe[0].Identity;
                msg.InitPool(identity.Length);
                msg.Put(identity, 0, identity.Length);
                msg.SetFlags(MsgFlags.More);

                m_identitySent = true;
            }

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

示例10: PushMsg

        public bool PushMsg(ref Msg msg)
        {
            Debug.Assert(m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub);

            //  The first message is identity.
            //  Let the session process it.

            m_session.PushMsg(ref msg);

            //  Inject the subscription message so that the ZMQ 2.x peer
            //  receives our messages.
            msg.InitPool(1);
            msg.Put((byte)1);

            bool isMessagePushed = m_session.PushMsg(ref msg);

            m_session.Flush();

            //  Once we have injected the subscription message, we can
            //  Divert the message flow back to the session.
            Debug.Assert(m_decoder != null);
            m_decoder.SetMsgSink(m_session);

            return isMessagePushed;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:25,代码来源:StreamEngine.cs

示例11: XRecv

        /// <summary>
        /// Receive a message. The <c>Recv</c> method calls this lower-level method to do the actual receiving.
        /// </summary>
        /// <param name="msg">the <c>Msg</c> to receive the message into</param>
        /// <returns><c>true</c> if the message was received successfully, <c>false</c> if there were no messages to receive</returns>
        protected override bool XRecv(ref Msg msg)
        {
            // If there is at least one
            if (m_pending.Count == 0)
                return false;

            msg.Close();

            byte[] first = m_pending.Dequeue();
            msg.InitPool(first.Length);

            msg.Put(first, 0, first.Length);

            return true;
        }
开发者ID:wangkai2014,项目名称:netmq,代码行数:20,代码来源:XPub.cs

示例12: InitGCOffset

        public void InitGCOffset()
        {
            var msg = new Msg();
            var bytes = new byte[200];
            msg.InitGC(bytes, 100, 50);

            Assert.AreEqual(50, msg.Size);
            Assert.AreEqual(MsgType.GC, msg.MsgType);
            Assert.AreEqual(MsgFlags.None, msg.Flags);
            Assert.AreSame(bytes, msg.Data);
            Assert.IsFalse(msg.HasMore);
            Assert.IsFalse(msg.IsDelimiter);
            Assert.IsFalse(msg.IsIdentity);
            Assert.IsTrue(msg.IsInitialised);

            var src = new byte[100];
            for (int i = 50; i < 100; i++) {
                src[i] = (byte)i;
            }
            msg.Put(src[50]);
            msg.Put(src[51], 1);
            msg.Put(src, 52, 2, 48);
            for (int i = 0; i < 50; i++) {
                msg[i] = (byte)(i + 50);
            }

            msg.Close();

            Assert.AreEqual(MsgType.Uninitialised, msg.MsgType);
            Assert.IsNull(msg.Data);
        }
开发者ID:cjkao,项目名称:netmq,代码行数:31,代码来源:MsgTests.cs

示例13: XRecv

        /// <summary>
        /// Receive a message. The <c>Recv</c> method calls this lower-level method to do the actual receiving.
        /// </summary>
        /// <param name="msg">the <c>Msg</c> to receive the message into</param>
        /// <returns><c>true</c> if the message was received successfully, <c>false</c> if there were no messages to receive</returns>
        protected override bool XRecv(ref Msg msg)
        {
            if (m_prefetched)
            {
                if (!m_identitySent)
                {
                    msg.Move(ref m_prefetchedId);
                    m_identitySent = true;
                }
                else
                {
                    msg.Move(ref m_prefetchedMsg);
                    m_prefetched = false;
                }

                return true;
            }

            var pipe = new Pipe[1];

            bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);

            if (!isMessageAvailable)
            {
                return false;
            }

            Debug.Assert(pipe[0] != null);
            Debug.Assert(!m_prefetchedMsg.HasMore);

            // We have received a frame with TCP data.
            // Rather than sending this frame, we keep it in prefetched
            // buffer and send a frame with peer's ID.
            byte[] identity = pipe[0].Identity;
            msg.InitPool(identity.Length);
            msg.Put(identity, 0, identity.Length);
            msg.SetFlags(MsgFlags.More);

            m_prefetched = true;
            m_identitySent = true;

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

示例14: XHasIn

        protected override bool XHasIn()
        {
            // We may already have a message pre-fetched.
            if (m_prefetched)
                return true;

            // Try to read the next message.
            // The message, if read, is kept in the pre-fetch buffer.
            var pipe = new Pipe[1];

            bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);

            if (!isMessageAvailable)
            {
                return false;
            }

            Debug.Assert(pipe[0] != null);
            Debug.Assert(!m_prefetchedMsg.HasMore);

            byte[] identity = pipe[0].Identity;
            m_prefetchedId = new Msg();
            m_prefetchedId.InitPool(identity.Length);
            m_prefetchedId.Put(identity, 0, identity.Length);
            m_prefetchedId.SetFlags(MsgFlags.More);

            m_prefetched = true;
            m_identitySent = false;

            return true;
        }
开发者ID:wangkai2014,项目名称:netmq,代码行数:31,代码来源:Stream.cs


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