Beispiel #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _lock.AcquireWriterLock();
         try
         {
             {
                 while (_outgoingQueue.Count > 0)
                 {
                     RtmpAsyncResult asyncResult = _outgoingQueue.Dequeue() as RtmpAsyncResult;
                     if (asyncResult != null)
                     {
                         asyncResult.SetComplete(new ObjectDisposedException(null));
                     }
                 }
                 _outgoingQueue.Clear();
             }
         }
         finally
         {
             _lock.ReleaseWriterLock();
         }
     }
     base.Dispose(disposing);
 }
Beispiel #2
0
        public override void EndWrite(IAsyncResult asyncResult)
        {
            RtmpAsyncResult result = asyncResult as RtmpAsyncResult;

            try
            {
                if (!asyncResult.IsCompleted)
                {
                    asyncResult.AsyncWaitHandle.WaitOne();

                    /*
                     * if (!asyncResult.AsyncWaitHandle.WaitOne(milliseconds, false))
                     * {
                     *  throw new TimeoutException();
                     * }
                     */
                }
                if (result.HasException())
                {
                    throw result.Exception;
                }
            }
            finally
            {
                TryBeginWrite();
            }
        }
Beispiel #3
0
        private void TryBeginWrite()
        {
            RtmpAsyncResult asyncResult = null;

            _lock.AcquireWriterLock();
            try
            {
                if (this.IsWriting)
                {
                    return;
                }
                if (_outgoingQueue.Count > 0)
                {
                    asyncResult = _outgoingQueue.Dequeue() as RtmpAsyncResult;
                    SetIsWriting(true);
                }
            }
            finally
            {
                _lock.ReleaseWriterLock();
            }
            try
            {
                if (asyncResult != null)
                {
                    this.InternalBeginWrite(asyncResult.Buffer, asyncResult.Offset, asyncResult.Count, new AsyncCallback(this.BeginWriteCallback), asyncResult);
                }
            }
            catch (Exception exception)
            {
                _lock.AcquireWriterLock();
                try
                {
                    SetIsWriting(false);
                }
                finally
                {
                    _lock.ReleaseWriterLock();
                }
                if (asyncResult != null)
                {
                    asyncResult.SetComplete(exception);
                }
                throw;
            }
        }
Beispiel #4
0
        private void BeginWriteCallback(IAsyncResult asyncResult)
        {
            RtmpAsyncResult asyncState = asyncResult.AsyncState as RtmpAsyncResult;

            if (asyncState != null)
            {
                try
                {
                    this.InternalEndWrite(asyncResult);
                    _lock.AcquireWriterLock();
                    try
                    {
                        SetIsWriting(false);
                    }
                    finally
                    {
                        _lock.ReleaseWriterLock();
                    }
                    asyncState.SetComplete(null);
                }
                catch (Exception exception)
                {
                    _lock.AcquireWriterLock();
                    try
                    {
                        SetIsWriting(false);
                    }
                    finally
                    {
                        _lock.ReleaseWriterLock();
                    }
                    asyncState.SetComplete(exception);
                }
                finally
                {
                    try
                    {
                        this.TryBeginWrite();
                    }
                    catch
                    {
                    }
                }
            }
        }
Beispiel #5
0
        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);
        }