public override void Write(byte[] buffer)
 {
     _lock.AcquireReaderLock();
     try
     {
         if (IsClosed || IsClosing || IsDisconnecting)
         {
             return; // Already shutting down.
         }
     }
     finally
     {
         _lock.ReleaseReaderLock();
     }
     if (log.IsDebugEnabled)
     {
         log.Debug(__Res.GetString(__Res.Rtmp_SocketSend, _connectionId));
     }
     try
     {
         //No need to lock, RtmpNetworkStream will handle Write locking
         _rtmpNetworkStream.Write(buffer, 0, buffer.Length);
         _writtenBytes.Increment(buffer.Length);
     }
     catch (ObjectDisposedException)
     {
         //After EndWrite, the underlying socket may be closed
     }
     catch (Exception ex)
     {
         HandleError(ex);
     }
     _lastAction = DateTime.Now;
 }