コード例 #1
0
ファイル: Pipe.cs プロジェクト: wxl-007/ShadowDota
        /// <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(ref msg);
                Debug.Assert(ok);
                Delimit();
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: Mailbox.cs プロジェクト: wxl-007/ShadowDota
        public Command Recv()
        {
            Command cmd = null;

            // bool ok =
            m_cpipe.Read(ref cmd);

            return(cmd);
        }
コード例 #3
0
ファイル: Mailbox.cs プロジェクト: wxl-007/ShadowDota
        public Command Recv(int timeout)
        {
            Command cmd = null;

            //  Try to get the command straight away.
            if (m_active)
            {
                m_cpipe.Read(ref cmd);

                if (cmd != null)
                {
                    return(cmd);
                }

                //  If there are no more commands available, switch into passive state.
                m_active = false;
                m_signaler.Recv();
            }


            //  Wait for signal from the command sender.
            bool rc = m_signaler.WaitEvent(timeout);

            if (!rc)
            {
                return(null);
            }

            //  We've got the signal. Now we can switch into active state.
            m_active = true;

            //  Get a command.
            bool ok = m_cpipe.Read(ref cmd);

            Debug.Assert(ok);

            return(cmd);
        }
コード例 #4
0
        public Mailbox(String name)
        {
            m_cpipe    = new YPipe <Command>(Config.CommandPipeGranularity, "mailbox");
            m_sync     = new object();
            m_signaler = new Signaler();

            //  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 = m_cpipe.Read();

            Debug.Assert(cmd == null);
            m_active = false;

            m_name = name;
        }
コード例 #5
0
ファイル: Mailbox.cs プロジェクト: wxl-007/ShadowDota
        public IOThreadMailbox([CanBeNull] string name, [NotNull] Proactor proactor, [NotNull] IMailboxEvent mailboxEvent)
        {
            m_proactor     = proactor;
            m_mailboxEvent = mailboxEvent;

            m_cpipe = new YPipe <Command>(Config.CommandPipeGranularity, "mailbox");
            m_sync  = new object();

            //  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.
            var cmd = new Command();

            bool ok = m_cpipe.Read(ref cmd);

            Debug.Assert(!ok);

            m_name = name;

            m_disposed = false;
        }
コード例 #6
0
ファイル: Pipe.cs プロジェクト: SPERONIS/Communication_Mono
        protected override void ProcessHiccup(object pipe)
        {
            //  Destroy old outpipe. Note that the read end of the pipe was already
            //  migrated to this thread.
            Debug.Assert(m_outboundPipe != null);
            m_outboundPipe.Flush();
            while (m_outboundPipe.Read() != null)
            {
            }

            //  Plug in the new outpipe.
            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);
            }
        }