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


C# Msg.SetFlags方法代码示例

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


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

示例1: XSend

        protected override bool XSend(Msg msg, SendReceiveOptions flags)
        {
            //  If we've sent a request and we still haven't got the reply,
            //  we can't send another request.
            if (m_receivingReply)
            {
                throw NetMQException.Create("Cannot send another request", ErrorCode.EFSM);
            }

            bool isMessageSent;

            //  First part of the request is the request identity.
            if (m_messageBegins)
            {
                Msg bottom = new Msg();
                bottom.SetFlags(MsgFlags.More);
                isMessageSent = base.XSend(bottom, 0);

                if (!isMessageSent)
                {
                    return false;
                }

                m_messageBegins = false;
            }

            bool more = msg.HasMore;

            isMessageSent = base.XSend(msg, flags);

            if (!isMessageSent)
            {
                return false;
            }
            //  If the request was fully sent, flip the FSM into reply-receiving state.
            else if (!more)
            {
                m_receivingReply = true;
                m_messageBegins = true;
            }

            return true;
        }
开发者ID:GianniBortoloBossini,项目名称:netmq,代码行数:43,代码来源:Req.cs

示例2: Send

        public void Send(Msg msg, SendReceiveOptions flags)
        {
            if (m_ctxTerminated)
            {
                throw TerminatingException.Create();
            }

            //  Check whether message passed to the function is valid.
            if (msg == null)
            {
                throw NetMQException.Create(ErrorCode.EFAULT);
            }

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

            //  Clear any user-visible flags that are set on the message.
            msg.ResetFlags(MsgFlags.More);

            //  At this point we impose the flags on the message.
            if ((flags & SendReceiveOptions.SendMore) > 0)
                msg.SetFlags(MsgFlags.More);

            //  Try to send the message.

            bool isMessageSent = XSend(msg, flags);

            if (isMessageSent)
            {
                return;
            }

            //  In case of non-blocking send we'll simply propagate
            //  the error - including EAGAIN - up the stack.
            if ((flags & SendReceiveOptions.DontWait) > 0 || m_options.SendTimeout == 0)
                throw AgainException.Create();

            //  Compute the time when the timeout should occur.
            //  If the timeout is infite, don't care.
            int timeout = m_options.SendTimeout;
            long end = timeout < 0 ? 0 : (Clock.NowMs() + timeout);

            //  Oops, we couldn't send the message. Wait for the next
            //  command, process it and try to send the message again.
            //  If timeout is reached in the meantime, return EAGAIN.
            while (true)
            {
                ProcessCommands(timeout, false);

                isMessageSent = XSend(msg, flags);
                if (isMessageSent)
                    break;

                if (timeout > 0)
                {
                    timeout = (int)(end - Clock.NowMs());
                    if (timeout <= 0)
                    {
                        throw AgainException.Create();
                    }
                }
            }
        }
开发者ID:hecwow,项目名称:netmq,代码行数:63,代码来源:SocketBase.cs

示例3: PushMsg

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

                if (!m_options.RecvIdentity)
                {
                    return;
                }
            }

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

            throw AgainException.Create();
        }
开发者ID:JayShelton,项目名称:netmq,代码行数:21,代码来源:SessionBase.cs

示例4: Send

        public bool Send(Msg msg, SendRecieveOptions flags)
        {
            if (m_ctxTerminated)
            {
                ZError.ErrorNumber = (ErrorNumber.ETERM);
                return false;
            }

            //  Check whether message passed to the function is valid.
            if (msg == null)
            {
                ZError.ErrorNumber = (ErrorNumber.EFAULT);
                throw new ArgumentException();
            }

            //  Process pending commands, if any.
            bool rc = ProcessCommands(0, true);
            if (!rc)
                return false;

            //  Clear any user-visible flags that are set on the message.
            msg.ResetFlags(MsgFlags.More);

            //  At this point we impose the flags on the message.
            if ((flags & SendRecieveOptions.SendMore) > 0)
                msg.SetFlags(MsgFlags.More);

            //  Try to send the message.
            rc = XSend(msg, flags);
            if (rc)
                return true;
            if (!ZError.IsError(ErrorNumber.EAGAIN))
                return false;

            //  In case of non-blocking send we'll simply propagate
            //  the error - including EAGAIN - up the stack.
            if ((flags & SendRecieveOptions.DontWait) > 0 || m_options.SendTimeout == 0)
                return false;

            //  Compute the time when the timeout should occur.
            //  If the timeout is infite, don't care.
            int timeout = m_options.SendTimeout;
            long end = timeout < 0 ? 0 : (Clock.NowMs() + timeout);

            //  Oops, we couldn't send the message. Wait for the next
            //  command, process it and try to send the message again.
            //  If timeout is reached in the meantime, return EAGAIN.
            while (true)
            {
                if (!ProcessCommands(timeout, false))
                    return false;

                rc = XSend(msg, flags);
                if (rc)
                    break;

                if (!ZError.IsError(ErrorNumber.EAGAIN))
                    return false;

                if (timeout > 0)
                {
                    timeout = (int)(end - Clock.NowMs());
                    if (timeout <= 0)
                    {
                        ZError.ErrorNumber = (ErrorNumber.EAGAIN);
                        return false;
                    }
                }
            }
            return true;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:71,代码来源:SocketBase.cs

示例5: Connect

        public void Connect(String addr)
        {
            if (m_ctxTerminated)
            {
                throw TerminatingException.Create();
            }

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

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

            CheckProtocol(protocol);

            if (protocol.Equals(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.
                int sndhwm;
                int rcvhwm;
                if (m_options.SendHighWatermark == 0 || peer.Options.ReceiveHighWatermark == 0)
                    sndhwm = 0;
                else
                    sndhwm = m_options.SendHighWatermark + peer.Options.ReceiveHighWatermark;
                if (m_options.ReceiveHighWatermark == 0 || peer.Options.SendHighWatermark == 0)
                    rcvhwm = 0;
                else
                    rcvhwm = m_options.ReceiveHighWatermark + peer.Options.SendHighWatermark;

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

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

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

                //  If required, send the identity of the local socket to the peer.
                if (m_options.RecvIdentity)
                {
                    Msg id = new Msg(m_options.IdentitySize);
                    id.Put(m_options.Identity, 0, m_options.IdentitySize);
                    id.SetFlags(MsgFlags.Identity);
                    bool written = pipes[1].Write(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;

                return;
            }

            //  Choose the I/O thread to run the session in.
            IOThread ioThread = ChooseIOThread(m_options.Affinity);
            if (ioThread == null)
            {
                throw NetMQException.Create("Empty IO Thread", ErrorCode.EMTHREAD);
            }
            Address paddr = new Address(protocol, address);

            //  Resolve address (if needed by the protocol)
            if (protocol.Equals(Address.TcpProtocol))
            {
                paddr.Resolved = (new TcpAddress());
                paddr.Resolved.Resolve(
                        address, m_options.IPv4Only);
            }
            else if (protocol.Equals(Address.IpcProtocol))
            {
                paddr.Resolved = (new IpcAddress());
                paddr.Resolved.Resolve(address, true);
//.........这里部分代码省略.........
开发者ID:hecwow,项目名称:netmq,代码行数:101,代码来源:SocketBase.cs

示例6: XSend

        protected override bool XSend(Msg msg, SendRecieveOptions flags)
        {
            //  If we've sent a request and we still haven't got the reply,
            //  we can't send another request.
            if (m_receivingReply) {
                throw new InvalidOperationException("Cannot send another request");
            }

            bool rc;

            //  First part of the request is the request identity.
            if (m_messageBegins) {
                Msg bottom = new Msg();
                bottom.SetFlags (MsgFlags.More);
                rc = base.XSend (bottom, 0);
                if (!rc)
                    return false;
                m_messageBegins = false;
            }

            bool more = msg.HasMore;

            rc = base.XSend (msg, flags);
            if (!rc)
                return rc;

            //  If the request was fully sent, flip the FSM into reply-receiving state.
            if (!more) {
                m_receivingReply = true;
                m_messageBegins = true;
            }

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

示例7: PushMsg

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

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

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

            ZError.ErrorNumber = (ErrorNumber.EAGAIN);
            return false;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:22,代码来源:SessionBase.cs

示例8: XRecv

        protected override bool XRecv(SendReceiveOptions flags, out Msg msg)
        {
            msg = null;
              if (m_prefetched)
              {
            if (!m_identitySent)
            {
              msg = m_prefetchedId;
              m_prefetchedId = null;
              m_identitySent = true;
            }
            else
            {
              msg = m_prefetchedMsg;
              m_prefetchedMsg = null;
              m_prefetched = false;
            }

            return true;
              }

              Pipe[] pipe = new Pipe[1];

              bool isMessageAvailable = m_fq.RecvPipe(pipe, out m_prefetchedMsg);

              if (!isMessageAvailable)
              {
            return false;
              }
              else if (m_prefetchedMsg == null)
              {
            return true;
              }

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

              //  We have received a frame with TCP data.
              //  Rather than sendig this frame, we keep it in prefetched
              //  buffer and send a frame with peer's ID.
              Blob identity = pipe[0].Identity;

              msg = new Msg(identity.Data, true);
              msg.SetFlags(MsgFlags.More);

              m_prefetched = true;
              m_identitySent = true;

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

示例9: Send

        /// <summary>
        /// Transmit the given Msg across the message-queueing system.
        /// If the msg fails to immediately send, then - if DontWait is specified and no SendTimeout was set
        /// then throw an AgainException.
        /// </summary>
        /// <param name="msg">the Msg to transmit</param>
        /// <param name="flags">a SendReceiveOptions: either don't specify DontWait, or set a timeout</param>
        public void Send(ref Msg msg, SendReceiveOptions flags)
        {
            CheckContextTerminated();

            //  Check whether message passed to the function is valid.
            if (!msg.IsInitialised)
                throw new FaultException("SocketBase.Send passed an uninitialised Msg.");

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

            //  Clear any user-visible flags that are set on the message.
            msg.ResetFlags(MsgFlags.More);

            //  At this point we impose the flags on the message.
            if ((flags & SendReceiveOptions.SendMore) > 0)
                msg.SetFlags(MsgFlags.More);

            //  Try to send the message.
            bool isMessageSent = XSend(ref msg);

            if (isMessageSent)
                return;

            //  In case of non-blocking send we'll simply propagate
            //  the error - including EAGAIN - up the stack.
            bool isDontWaitSet = (flags & SendReceiveOptions.DontWait) > 0;
            if (isDontWaitSet || m_options.SendTimeout == 0)
            {
            #if DEBUG
                string xMsg;
                if (isDontWaitSet && m_options.SendTimeout == 0)
                    xMsg = "SocketBase.Send failed, and DontWait is true AND SendTimeout is 0.";
                else if (isDontWaitSet)
                    xMsg = "SocketBase.Send failed and DontWait is specified.";
                else
                    xMsg = "SocketBase.Send failed and no SendTimeout is specified.";
                throw new AgainException(innerException: null, message: xMsg);
            #else
                throw new AgainException(innerException: null, message: "SocketBase.Send failed");
            #endif
            }

            //  Compute the time when the timeout should occur.
            //  If the timeout is infinite, don't care.
            int timeout = m_options.SendTimeout;
            long end = timeout < 0 ? 0 : (Clock.NowMs() + timeout);

            //  Oops, we couldn't send the message. Wait for the next
            //  command, process it and try to send the message again.
            //  If timeout is reached in the meantime, return EAGAIN.
            while (true)
            {
                ProcessCommands(timeout, false);

                isMessageSent = XSend(ref msg);

                if (isMessageSent)
                    break;

                if (timeout <= 0)
                    continue;

                timeout = (int)(end - Clock.NowMs());

                if (timeout <= 0)
                    throw new AgainException(innerException: null, message: "SocketBase.Send failed and timeout <= 0");
            }
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:76,代码来源:SocketBase.cs

示例10: 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.
              Pipe[] pipe = new Pipe[1];

              bool isMessageAvailable = m_fq.RecvPipe(pipe, out m_prefetchedMsg);

              if (!isMessageAvailable)
              {
            return false;
              }

              if (m_prefetchedMsg == null)
              {
            return false;
              }

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

              Blob identity = pipe[0].Identity;
              m_prefetchedId = new Msg(identity.Data);
              m_prefetchedId.SetFlags(MsgFlags.More);

              m_prefetched = true;
              m_identitySent = false;

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

示例11: XRecv

        protected override bool XRecv(SendReceiveOptions flags, out Msg msg)
        {
            msg = null;
            if (m_prefetched)
            {
                if (!m_identitySent)
                {
                    msg = m_prefetchedId;
                    m_prefetchedId = null;
                    m_identitySent = true;
                }
                else
                {
                    msg = m_prefetchedMsg;
                    m_prefetchedMsg = null;
                    m_prefetched = false;
                }
                m_moreIn = msg.HasMore;
                return true;
            }

            Pipe[] pipe = new Pipe[1];

            bool isMessageAvailable = m_fq.RecvPipe(pipe, out 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.
            //  TODO: handle the situation when the peer changes its identity.
            while (isMessageAvailable && msg != null && msg.IsIdentity)
                isMessageAvailable = m_fq.RecvPipe(pipe, out msg);

            if (!isMessageAvailable)
            {
                return false;
            }
            else if (msg == null)
            {
                return true;
            }

            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 = msg;

                m_prefetched = true;

                Blob identity = pipe[0].Identity;
                msg = new Msg(identity.Data);
                msg.SetFlags(MsgFlags.More);
                m_identitySent = true;
            }

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

示例12: 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.
            Pipe[] pipe = new Pipe[1];

            bool isMessageAvailable = m_fq.RecvPipe(pipe, out m_prefetchedMsg);

            if (!isMessageAvailable)
            {
                return false;
            }

            //  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 (m_prefetchedMsg != null && m_prefetchedMsg.IsIdentity)
            {
                isMessageAvailable = m_fq.RecvPipe(pipe, out m_prefetchedMsg);

                if (!isMessageAvailable)
                {
                    return false;
                }
            }

            if (m_prefetchedMsg == null)
            {
                return false;
            }

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

            Blob identity = pipe[0].Identity;
            m_prefetchedId = new Msg(identity.Data);
            m_prefetchedId.SetFlags(MsgFlags.More);

            m_prefetched = true;
            m_identitySent = false;

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

示例13: Receive

        public void Receive(ref Msg msg, SendReceiveOptions options)
        {
            LastOptions = options;

            byte[] bytes = m_frames.Dequeue();

            msg.InitGC(bytes, bytes.Length);

            if (m_frames.Count != 0)
                msg.SetFlags(MsgFlags.More);
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:11,代码来源:ReceivingSocketExtensionsTests.cs

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