private void OnReceivedCallback(object state) { if (log.get_IsDebugEnabled()) { log.Debug(__Res.GetString("Rtmp_SocketReadProcessing", new object[] { base._connectionId })); } if (log.get_IsDebugEnabled()) { log.Debug("Begin handling packet " + this.ToString()); } if (!this.IsTunnelingDetected) { this.IsTunnelingDetected = true; byte num = this._readBuffer.Get(0); this.SetIsTunneled(num != 3); } try { if (!this.IsTunneled) { List <object> list = RtmpProtocolDecoder.DecodeBuffer(base.Context, this._readBuffer); if ((list != null) && (list.Count > 0)) { foreach (object obj2 in list) { if (obj2 is ByteBuffer) { ByteBuffer buf = obj2 as ByteBuffer; this.Send(buf); } else { FluorineRtmpContext.Initialize(this); this._rtmpServer.RtmpHandler.MessageReceived(this, obj2); } } } } else { this.HandleRtmpt(); } } catch (Exception exception) { this.HandleError(exception); } if (log.get_IsDebugEnabled()) { log.Debug("End handling packet " + this.ToString()); } this.BeginReceive(false); }
private void OnReceivedCallback(object state) { _lock.AcquireReaderLock(); try { if (IsClosed || IsClosing || IsDisconnecting) { return; // Already shutting down. } } finally { _lock.ReleaseReaderLock(); } log4net.ThreadContext.Properties["ClientIP"] = this.RemoteEndPoint; if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.Rtmp_SocketReadProcessing, _connectionId)); } if (!IsTunnelingDetected) { IsTunnelingDetected = true; byte rtmpDetect = _readBuffer.Get(0); bool encrypted = (rtmpDetect == 0x06); //rtmpe? if (!encrypted) { SetIsTunneled(rtmpDetect != 0x3); } if (!IsTunneled) { //For tunneled connections we do not really need a session for this connection _session = _endpoint.GetMessageBroker().SessionManager.CreateSession(this); } } try { if (!IsTunneled) { FluorineRtmpContext.Initialize(this); #if !(NET_1_1) List <object> result = null; #else ArrayList result = null; #endif try { result = RtmpProtocolDecoder.DecodeBuffer(this.Context, _readBuffer); } catch (HandshakeFailedException hfe) { #if !SILVERLIGHT if (log.IsDebugEnabled) { log.Debug(string.Format("Handshake failed: {0}", hfe.Message)); } #endif // Clear buffer if something is wrong in protocol decoding. _readBuffer.Clear(); this.Close(); return; } catch (Exception ex) { // Catch any exception in the decoding then clear the buffer to eliminate memory leaks when we can't parse protocol // Also close Connection because we can't parse data from it #if !SILVERLIGHT log.Error("Error decoding buffer", ex); #endif // Clear buffer if something is wrong in protocol decoding. _readBuffer.Clear(); this.Close(); return; } if (result != null && result.Count > 0) { foreach (object obj in result) { if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.Rtmp_BeginHandlePacket, _connectionId)); } if (obj is ByteBuffer) { ByteBuffer buf = obj as ByteBuffer; Write(buf); } else if (obj is byte[]) { Write(obj as byte[]); } else { _rtmpServer.RtmpHandler.MessageReceived(this, obj); } if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.Rtmp_EndHandlePacket, _connectionId)); } } } } else { //FluorineRtmpContext.Initialize(this); RtmptRequest rtmptRequest = RtmptProtocolDecoder.DecodeBuffer(this, _readBuffer); if (rtmptRequest != null) { HandleRtmpt(rtmptRequest); } } } catch (Exception ex) { HandleError(ex); } //Ready to receive again BeginReceive(false); }