Ejemplo n.º 1
0
        private void DoRun()
        {
            switch (runMode)
            {
            case MODE_SEND:
                // write the current (in progress) op into the write buffer
                // - or -
                // start writing a new one (until we run out of ops or space)
                if (!ContinueWritingCurrentOp())
                {
                    while (!socket.WriteBuffer.IsFull)
                    {
                        var data = GetNextOp();
                        if (data.IsEmpty)
                        {
                            break;
                        }

                        counterDequeuePerSec.Increment();
                        if (trace.IsEnabled())
                        {
                            trace.DequeueWriteOp(name);
                        }
                        WriteOp(data);
                    }
                }

                // did we write anything?
                if (socket.WriteBuffer.Position > 0)
                {
                    FlushWriteBuffer();
                }
                else
                {
                    // did not have any ops to send, quit
                    MarkAsReady();
                }

                break;

            case MODE_RECEIVE:
                // do we have ops queued to be read?
                if (readQueue.Count > 0)
                {
                    PerformReceive();
                }
                else
                {
                    // nothing to receive, switch to send mode
                    Volatile.Write(ref runMode, MODE_SEND);
                    goto case MODE_SEND;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        protected virtual OpQueueEntry GetNextOp()
        {
            OpQueueEntry data;

            if (writeQueue.TryDequeue(out data))
            {
                #region Diagnostics
                npm.DequeueWriteOp();
                CoreEventSource.DequeueWriteOp(name);
                #endregion

                return(data);
            }

            return(OpQueueEntry.Empty);
        }