Exemplo n.º 1
0
        public TimestampedMsg <In> Peek()
        {
            if (_broken)
            {
                throw new ConnectionReadError();
            }
            TimestampedMsg <In> msg = _queue.Peek();

            if (msg == null)
            {
                _broken = true;
                throw new ConnectionReadError();
            }
            return(msg);
        }
Exemplo n.º 2
0
 public bool PeekWithTimeout(TimeSpan timeout, out TimestampedMsg <In> msg)
 {
     if (_broken)
     {
         throw new ConnectionReadError();
     }
     if (!_queue.PeekWithTimeout(timeout, out msg))
     {
         return(false);
     }
     if (msg == null)
     {
         _broken = true;
         throw new ConnectionReadError();
     }
     return(true);
 }
Exemplo n.º 3
0
        // Processes the reply to the last request that we sent.
        // It's the caller's responsibility to guarantee that this message is indeed the
        // reply and not some other unrelated message.
        public void OnReply(TimestampedMsg <Req> msg)
        {
            Condition.Requires(msg, "msg").IsNotNull();
            Callback cb;

            lock (_monitor)
            {
                if (_inflight == null)
                {
                    _log.Error("Received response to a request we didn't send: ({0}) {1}", msg.Value.GetType(), msg.Value);
                    return;
                }
                cb        = _inflight;
                _inflight = null;
            }
            _connection.Scheduler.Schedule(() => cb.Done(msg));
            _queue.TryProcess();
        }
Exemplo n.º 4
0
 // Runs in the scheduler thread.
 void HandleMessage(IConnection <In, Out> connection, TimestampedMsg <In> msg)
 {
     // We can read _connection without a lock because we are in the scheduler thread.
     // _connection can't be modified while we are running.
     if (!Object.ReferenceEquals(connection, _connection))
     {
         _log.Info("Message belongs to a stale connection. Dropping it.");
         return;
     }
     if (msg == null)
     {
         // Null message means unrecoverable network read error.
         Reconnect();
     }
     else
     {
         // If it throws, that's OK. The exception will be caught and logged
         // by the scheduler.
         OnMessage?.Invoke(msg);
     }
 }
Exemplo n.º 5
0
 public void Push(TimestampedMsg <In> msg)
 {
     _queue.Push(msg);
 }