示例#1
0
            public void Flush(LoopbackSession session)
            {
                IWriteRequestQueue queue = session.WriteRequestQueue;

                if (!session.Closing)
                {
                    lock (session.Lock)
                    {
                        try
                        {
                            if (queue.IsEmpty(session))
                            {
                                return;
                            }

                            IWriteRequest req;
                            DateTime      currentTime = DateTime.Now;
                            while ((req = queue.Poll(session)) != null)
                            {
                                Object m = req.Message;
                                _chain.PushEvent(new IoEvent(IoEventType.MessageSent, session, req), false);
                                session.RemoteSession.FilterChain.FireMessageReceived(GetMessageCopy(m));
                                IoBuffer buf = m as IoBuffer;
                                if (buf != null)
                                {
                                    session.IncreaseWrittenBytes(buf.Remaining, currentTime);
                                }
                            }
                        }
                        finally
                        {
                            if (_chain._flushEnabled)
                            {
                                _chain.FlushEvents();
                            }
                        }
                    }

                    FlushPendingDataQueues(session);
                }
                else
                {
                    List <IWriteRequest> failedRequests = new List <IWriteRequest>();
                    IWriteRequest        req;
                    while ((req = queue.Poll(session)) != null)
                    {
                        failedRequests.Add(req);
                    }

                    if (failedRequests.Count > 0)
                    {
                        WriteToClosedSessionException cause = new WriteToClosedSessionException(failedRequests);
                        foreach (IWriteRequest r in failedRequests)
                        {
                            r.Future.Exception = cause;
                        }
                        session.FilterChain.FireExceptionCaught(cause);
                    }
                }
            }
            public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
            {
                AbstractIoSession s = session as AbstractIoSession;

                if (s != null)
                {
                    // Maintain counters.
                    IoBuffer buffer = writeRequest.Message as IoBuffer;
                    if (buffer != null)
                    {
                        // I/O processor implementation will call buffer.Reset()
                        // it after the write operation is finished, because
                        // the buffer will be specified with messageSent event.
                        buffer.Mark();
                        Int32 remaining = buffer.Remaining;
                        if (remaining == 0)
                        {
                            // Zero-sized buffer means the internal message delimiter
                            s.IncreaseScheduledWriteMessages();
                        }
                        else
                        {
                            s.IncreaseScheduledWriteBytes(remaining);
                        }
                    }
                    else
                    {
                        s.IncreaseScheduledWriteMessages();
                    }
                }

                IWriteRequestQueue writeRequestQueue = session.WriteRequestQueue;

                if (session.WriteSuspended)
                {
                    writeRequestQueue.Offer(session, writeRequest);
                }
                else if (writeRequestQueue.IsEmpty(session))
                {
                    // We can write directly the message
                    session.Processor.Write(session, writeRequest);
                }
                else
                {
                    writeRequestQueue.Offer(session, writeRequest);
                    session.Processor.Flush(session);
                }
            }
示例#3
0
 /// <inheritdoc/>
 public Boolean IsEmpty(IoSession session)
 {
     return(_queue.IsEmpty(session));
 }