public void ReceiveLoop() { StreamBuffer streamBuffer = new StreamBuffer(base.MTU); byte[] array = new byte[9]; while (base.State == PhotonSocketState.Connected) { streamBuffer.SetLength(0L); try { int i = 0; int num = 0; while (i < 9) { try { num = this.sock.Receive(array, i, 9 - i, SocketFlags.None); } catch (SocketException ex) { bool flag = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected && ex.SocketErrorCode == SocketError.WouldBlock; if (flag) { bool flag2 = base.ReportDebugOfLevel(DebugLevel.ALL); if (flag2) { base.EnqueueDebugReturn(DebugLevel.ALL, "ReceiveLoop() got a WouldBlock exception. This is non-fatal. Going to continue."); } continue; } throw; } i += num; bool flag3 = num == 0; if (flag3) { throw new SocketException(10054); } } bool flag4 = array[0] == 240; if (flag4) { base.HandleReceivedDatagram(array, array.Length, true); } else { int num2 = (int)array[1] << 24 | (int)array[2] << 16 | (int)array[3] << 8 | (int)array[4]; bool trafficStatsEnabled = this.peerBase.TrafficStatsEnabled; if (trafficStatsEnabled) { bool flag5 = array[5] == 0; bool flag6 = flag5; if (flag6) { this.peerBase.TrafficStatsIncoming.CountReliableOpCommand(num2); } else { this.peerBase.TrafficStatsIncoming.CountUnreliableOpCommand(num2); } } bool flag7 = base.ReportDebugOfLevel(DebugLevel.ALL); if (flag7) { base.EnqueueDebugReturn(DebugLevel.ALL, "message length: " + num2); } streamBuffer.SetCapacityMinimum(num2 - 7); streamBuffer.Write(array, 7, i - 7); i = 0; num2 -= 9; while (i < num2) { try { num = this.sock.Receive(streamBuffer.GetBuffer(), (int)streamBuffer.Position, num2 - i, SocketFlags.None); } catch (SocketException ex2) { bool flag8 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected && ex2.SocketErrorCode == SocketError.WouldBlock; if (flag8) { bool flag9 = base.ReportDebugOfLevel(DebugLevel.ALL); if (flag9) { base.EnqueueDebugReturn(DebugLevel.ALL, "ReceiveLoop() got a WouldBlock exception. This is non-fatal. Going to continue."); } continue; } throw; } streamBuffer.Position += (long)num; i += num; bool flag10 = num == 0; if (flag10) { throw new SocketException(10054); } } base.HandleReceivedDatagram(streamBuffer.ToArray(), (int)streamBuffer.Length, false); bool flag11 = base.ReportDebugOfLevel(DebugLevel.ALL); if (flag11) { base.EnqueueDebugReturn(DebugLevel.ALL, "TCP < " + streamBuffer.Length + ((streamBuffer.Length == (long)(num2 + 2)) ? " OK" : " BAD")); } } } catch (SocketException ex3) { bool flag12 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected; if (flag12) { bool flag13 = base.ReportDebugOfLevel(DebugLevel.ERROR); if (flag13) { base.EnqueueDebugReturn(DebugLevel.ERROR, "Receiving failed. SocketException: " + ex3.SocketErrorCode); } bool flag14 = ex3.SocketErrorCode == SocketError.ConnectionReset || ex3.SocketErrorCode == SocketError.ConnectionAborted; if (flag14) { base.HandleException(StatusCode.DisconnectByServer); } else { base.HandleException(StatusCode.ExceptionOnReceive); } } } catch (Exception ex4) { bool flag15 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected; if (flag15) { bool flag16 = base.ReportDebugOfLevel(DebugLevel.ERROR); if (flag16) { base.EnqueueDebugReturn(DebugLevel.ERROR, string.Concat(new object[] { "Receive issue. State: ", base.State, ". Server: '", base.ServerAddress, "' Exception: ", ex4 })); } base.HandleException(StatusCode.ExceptionOnReceive); } } } this.Disconnect(); }