Beispiel #1
0
        /// <summary>
        /// Checks if there is at least one message to read in the pipe.
        /// </summary>
        /// <returns> Returns <c>true</c> if there is at least one message to read in the pipe; <c>false</c> otherwise. </returns>
        public bool CheckRead()
        {
            if (!m_inActive || (m_state != State.Active && m_state != State.Pending))
            {
                return(false);
            }

            // Check if there's an item in the pipe.
            if (!m_inboundPipe.CheckRead())
            {
                m_inActive = false;
                return(false);
            }

            // If the next item in the pipe is message delimiter,
            // initiate termination process.
            if (m_inboundPipe.Probe().IsDelimiter)
            {
                var  msg = new Msg();
                bool ok  = m_inboundPipe.Read(out msg);
                Debug.Assert(ok);
                Delimit();
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public IOThreadMailbox([NotNull] string name, [NotNull] Proactor proactor, [NotNull] IMailboxEvent mailboxEvent)
        {
            m_proactor     = proactor;
            m_mailboxEvent = mailboxEvent;

            // Get the pipe into passive state. That way, if the users starts by
            // polling on the associated file descriptor it will get woken up when
            // new command is posted.
            Command cmd;
            bool    ok = m_commandPipe.Read(out cmd);

            Debug.Assert(!ok);

#if DEBUG
            m_name = name;
#endif
        }
Beispiel #3
0
        /// <summary>
        /// Create a new Mailbox with the given name.
        /// </summary>
        /// <param name="name">the name to give this new Mailbox</param>
        public Mailbox([NotNull] string name)
        {
            // Get the pipe into passive state. That way, if the users starts by
            // polling on the associated file descriptor it will get woken up when
            // new command is posted.

            Command cmd;
            bool    ok = m_commandPipe.Read(out cmd);

            Debug.Assert(!ok);

            m_active = false;

#if DEBUG
            m_name = name;
#endif
        }
Beispiel #4
0
        /// <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.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);
            }
        }