public override void Close()
 {
     _lock.AcquireWriterLock();
     try
     {
         if (IsClosed || IsClosing)
         {
             return; // Already shutting down.
         }
         SetIsClosing(true);
     }
     finally
     {
         _lock.ReleaseWriterLock();
     }
     FluorineRtmpContext.Initialize(this);
     base.Close();
     _rtmpServer.OnConnectionClose(this);
     _rtmpNetworkStream.Close();
     _lock.AcquireWriterLock();
     try
     {
         SetIsClosed(true);
         SetIsClosing(false);
         SetIsDisconnecting(false);
     }
     finally
     {
         _lock.ReleaseWriterLock();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Free managed resources.
 /// </summary>
 protected override void Free()
 {
     try
     {
         _lock.AcquireWriterLock();
         if (_queue != null)
         {
             while (_queue.Count > 0)
             {
                 try
                 {
                     using (_queue.Dequeue() as IDisposable)
                     {
                     }
                 }
                 catch (Exception ex)
                 {
                     Unreferenced.Parameter(ex);
                 }
             }
         }
     }
     finally
     {
         _lock.ReleaseWriterLock();
     }
     base.Free();
 }
Exemplo n.º 3
0
 public void Clear()
 {
     kiberCacheLock.AcquireWriterLock();
     try {
         TilesInMemory.Clear();
     }
     finally {
         kiberCacheLock.ReleaseWriterLock();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes client.
 /// </summary>
 /// <param name="client">Client bound to connection.</param>
 public void Initialize(IClient client)
 {
     try {
         _readerWriterLock.AcquireWriterLock();
         if (this.Client != null)
         {
             // Unregister old client
             this.Client.Unregister(this);
         }
         _client = client;
         // Register new client
         _client.Register(this);
     } finally {
         _readerWriterLock.ReleaseWriterLock();
     }
 }
Exemplo n.º 5
0
 void AddTileToMemoryCache(RawTile tile, MemoryStream data)
 {
     kiberCacheLock.AcquireWriterLock();
     try
     {
         if (!TilesInMemory.ContainsKey(tile))
         {
             TilesInMemory.Add(tile, Stuff.CopyStream(data, true));
         }
     }
     finally
     {
         kiberCacheLock.ReleaseWriterLock();
     }
 }
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            RtmpAsyncResult asyncResult = null;

            _lock.AcquireWriterLock();
            try {
                if (this.IsClosed)
                {
                    throw new ObjectDisposedException(null);
                }
                asyncResult = new RtmpAsyncResult(callback, state, buffer, offset, count);
                _outgoingQueue.Enqueue(asyncResult);
            } finally {
                _lock.ReleaseWriterLock();
            }
            TryBeginWrite();
            return(asyncResult);
        }
Exemplo n.º 7
0
 internal WriterLock(FastReaderWriterLock lockObj)
 {
     _lockObj = lockObj;
     _lockObj.AcquireWriterLock();
 }
Exemplo n.º 8
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);
        }