示例#1
0
 public void RealClose()
 {
     _lock.AcquireReaderLock();
     try
     {
         if (!IsClosing)
             return;
     }
     finally
     {
         _lock.ReleaseReaderLock();
     }
     try
     {
         _lock.AcquireWriterLock();
         if (_buffer != null)
         {
             _buffer.Dispose();
             _buffer = null;
         }
         if (_pendingMessages != null)
         {
             _pendingMessages.Clear();
             _pendingMessages = null;
         }
         _rtmptServer.RemoveConnection(this.ConnectionId);
     }
     finally
     {
         _lock.ReleaseWriterLock();
     }
     base.Close();
     _lock.AcquireWriterLock();
     try
     {
         SetIsClosed(true);
         SetIsClosing(false);
     }
     finally
     {
         _lock.ReleaseWriterLock();
     }
 }
示例#2
0
        public override void Write(byte[] buffer)
        {
            _lock.AcquireReaderLock();
            try
            {
                if (IsClosed || IsClosing)
                    return;
            }
            finally
            {
                _lock.ReleaseReaderLock();
            }

            try
            {
                _lock.AcquireWriterLock();
                if (_pendingMessages == null)
                    _pendingMessages = new LinkedList();
                _pendingMessages.Add(new PendingData(buffer));
            }
            finally
            {
                _lock.ReleaseWriterLock();
            }            
        }
示例#3
0
        public ByteBuffer GetPendingMessages(int targetSize)
        {
            ByteBuffer result = null;
            LinkedList toNotify = new LinkedList();
            try
            {
                _lock.AcquireWriterLock();
                if (_pendingMessages == null || _pendingMessages.Count == 0)
                {
                    _noPendingMessages += 1;
                    if (_noPendingMessages > INCREASE_POLLING_DELAY_COUNT)
                    {
                        if (_pollingDelay == 0)
                            _pollingDelay = 1;
                        _pollingDelay = (byte)(_pollingDelay * 2);
                        if (_pollingDelay > MAX_POLLING_DELAY)
                            _pollingDelay = MAX_POLLING_DELAY;
                    }
                    return null;
                }
                _noPendingMessages = 0;
                _pollingDelay = INITIAL_POLLING_DELAY;

                if (_pendingMessages.Count == 0)
                    return null;
                if (log.IsDebugEnabled)
                    log.Debug(__Res.GetString(__Res.Rtmpt_ReturningMessages, _pendingMessages.Count));
                result = ByteBuffer.Allocate(2048);
                while (_pendingMessages.Count > 0)
                {
                    PendingData pendingData = _pendingMessages[0] as PendingData;
                    _pendingMessages.RemoveAt(0);
                    if (pendingData.Buffer is ByteBuffer)
                        result.Put(pendingData.Buffer as ByteBuffer);
                    if (pendingData.Buffer is byte[])
                        result.Put(pendingData.Buffer as byte[]);
                    if (pendingData.Packet != null)
                        toNotify.Add(pendingData.Packet);

                    if ((result.Position > targetSize))
                        break;
                }
            }
            finally
            {
                _lock.ReleaseWriterLock();
            }
            if (toNotify != null)
            {
                foreach (object message in toNotify)
                {
                    try
                    {
                        _handler.MessageSent(this, message);
                    }
                    catch (Exception ex)
                    {
                        log.Error(__Res.GetString(__Res.Rtmpt_NotifyError), ex);
                        continue;
                    }
                }
            }
            result.Flip();
            _writtenBytes.Increment(result.Limit);
            return result;
        }
示例#4
0
 public override void Write(RtmpPacket packet)
 {
     _lock.AcquireReaderLock();
     try
     {
         if (IsClosed || IsClosing)
             return;
     }
     finally
     {
         _lock.ReleaseReaderLock();
     }
     try
     {
         _lock.AcquireWriterLock();
         ByteBuffer data;
         try
         {
             data = RtmpProtocolEncoder.Encode(this.Context, packet);
         }
         catch (Exception ex)
         {
             log.Error("Could not encode message " + packet, ex);
             return;
         }
         // Mark packet as being written
         WritingMessage(packet);
         if (_pendingMessages == null)
             _pendingMessages = new LinkedList();
         _pendingMessages.Add(new PendingData(data, packet));
     }
     finally
     {
         _lock.ReleaseWriterLock();
     }
 }
示例#5
0
 public LinkedListEnumerator(LinkedList ll)
 {
     this._ll = ll;
     this._modId = ll._modId;
     this._current = _ll._rootNode;
 }