Esempio n. 1
0
        /// <summary>
        /// Get a message from FairQueuing data structure
        /// </summary>
        /// <param name="msg">a Msg 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)
        {
            bool received = m_fairQueueing.Recv(ref msg);

            // Drop any messages with more flag
            while (received && msg.HasMore)
            {
                // drop all frames of the current multi-frame message
                received = m_fairQueueing.Recv(ref msg);

                while (received && msg.HasMore)
                {
                    received = m_fairQueueing.Recv(ref msg);
                }

                // get the new message
                if (received)
                {
                    received = m_fairQueueing.Recv(ref msg);
                }
            }

            if (!received)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        /// <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)
        {
            bool received = m_fairQueueing.RecvPipe(ref msg, out var pipe);

            // Drop any messages with more flag
            while (received && msg.HasMore)
            {
                // drop all frames of the current multi-frame message
                received = m_fairQueueing.Recv(ref msg);

                while (received && msg.HasMore)
                {
                    received = m_fairQueueing.Recv(ref msg);
                }

                // get the new message
                if (received)
                {
                    received = m_fairQueueing.RecvPipe(ref msg, out pipe);
                }
            }

            if (!received)
            {
                return(false);
            }

            Assumes.NotNull(pipe);
            msg.RoutingId = pipe.RoutingId;

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// If there's a pre-fetched message, snatch that.
        /// Otherwise, dump any identity messages and get the first non-identity message,
        /// or return false if there are no messages available.
        /// </summary>
        /// <param name="msg">a Msg to receive the message into</param>
        /// <returns>false if there were no messages to receive</returns>
        private bool ReceiveInternal(ref Msg msg)
        {
            // If there is a prefetched message, return it.
            if (m_prefetched)
            {
                msg.Move(ref m_prefetchedMsg);

                m_prefetched = false;

                return(true);
            }

            // DEALER socket doesn't use identities. We can safely drop it and
            while (true)
            {
                bool isMessageAvailable = m_fairQueueing.Recv(ref msg);

                if (!isMessageAvailable)
                {
                    return(false);
                }

                // Stop when we get any message that is not an Identity.
                if (!msg.IsIdentity)
                {
                    break;
                }
            }

            return(true);
        }
Esempio n. 4
0
        private bool ReceiveInternal(SendReceiveOptions flags, ref Msg msg)
        {
            //  If there is a prefetched message, return it.
            if (m_prefetched)
            {
                msg.Move(ref m_prefetchedMsg);

                m_prefetched = false;

                return(true);
            }

            //  DEALER socket doesn't use identities. We can safely drop it and
            while (true)
            {
                bool isMessageAvailable = m_fairQueueing.Recv(ref msg);

                if (!isMessageAvailable)
                {
                    return(false);
                }

                if ((msg.Flags & MsgFlags.Identity) == 0)
                {
                    break;
                }
            }

            return(true);
        }
Esempio n. 5
0
        /// <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's already a message prepared by a previous call to zmq_poll,
            // return it straight ahead.

            if (m_hasMessage)
            {
                msg.Move(ref m_message);
                m_hasMessage = false;
                m_moreIn     = msg.HasMore;
                return(true);
            }

            // TODO: This can result in infinite loop in the case of continuous
            // stream of non-matching messages which breaks the non-blocking recv
            // semantics.
            while (true)
            {
                // Get a message using fair queueing algorithm.
                bool isMessageAvailable = m_fairQueueing.Recv(ref msg);

                // If there's no message available, return immediately.
                // The same when error occurs.
                if (!isMessageAvailable)
                {
                    return(false);
                }

                // Check whether the message matches at least one subscription.
                // Non-initial parts of the message are passed
                if (m_moreIn || !m_options.Filter || Match(msg))
                {
                    m_moreIn = msg.HasMore;
                    return(true);
                }

                // Message doesn't match. Pop any remaining parts of the message
                // from the pipe.
                while (msg.HasMore)
                {
                    isMessageAvailable = m_fairQueueing.Recv(ref msg);

                    Debug.Assert(isMessageAvailable);
                }
            }
        }
Esempio n. 6
0
 protected override bool XRecv(SendReceiveOptions flags, ref Msg msg)
 {
     return(m_fairQueueing.Recv(ref msg));
 }
Esempio n. 7
0
 /// <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)
 {
     return(m_fairQueueing.Recv(ref msg));
 }