private void ReceivePackets() { BufferChunk bc = null; while (true) { try { bc = GetBuffer(); EndPoint ep; rtpNetworkListener.ReceiveFrom(bc, out ep); receivedPackets.Enqueue(new object[] { bc, ep }); newPacket.Set(); unchecked { pcPackets++; } } catch (PoolExhaustedException e) { LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.UnboundedGrowth); return; // Exit the thread gracefully } catch (System.Net.Sockets.SocketException e) { ReturnBuffer(bc); // Something other than - No data received before timeout if (e.ErrorCode != 10060) { Object[] args = new Object[] { this, new RtpEvents.HiddenSocketExceptionEventArgs((RtpSession)rtpSession, e) }; EventThrower.QueueUserWorkItem(new RtpEvents.RaiseEvent(RtpEvents.RaiseHiddenSocketExceptionEvent), args); LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error); } } catch (Exception e) { if (!(e is ThreadAbortException)) { ReturnBuffer(bc); LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error); } } } }
public void ListenThread() { CompoundPacket compoundPacket = new CompoundPacket(); EndPoint endPoint = null; while (!disposed) { try { // Reset the packet for the next round of data compoundPacket.Reset(); // Wait for data off the wire rtcpNetworkListener.ReceiveFrom(compoundPacket.Buffer, out endPoint); #region Fault Injection #if FaultInjection // Drop packets if (rtpSession.DropPacketsPercent > 0) { if (rtpSession.Rnd.Next(1, 100) <= rtpSession.DropPacketsPercent) { continue; } } #endif #endregion Fault Injection // Parse the data and rigorously validate it compoundPacket.ParseBuffer(); // Pass it on to the rtpSession to analyze and distribute data rtpSession.ProcessCompoundPacket(compoundPacket, ((IPEndPoint)endPoint).Address); } catch (System.Net.Sockets.SocketException e) { // No data received before timeout if (e.ErrorCode == 10060) { rtpSession.RaiseNetworkTimeoutEvent("Rtcp"); } // We get 10054 socket exceptions in some situations during unicast connections. Ignore them for now. // Pri2: Find a better solution for the unicast socket exceptions else if (e.ErrorCode == 10054 && !Utility.IsMulticast(rtcpNetworkListener.ExternalInterface)) { continue; } else { Object[] args = new Object[] { this, new RtpEvents.HiddenSocketExceptionEventArgs((RtpSession)rtpSession, e) }; EventThrower.QueueUserWorkItem(new RtpEvents.RaiseEvent(RtpEvents.RaiseHiddenSocketExceptionEvent), args); LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error); } } catch (RtcpHeader.RtcpHeaderException e) { // TODO - this is a pretty serious error - what should we do - exit thread, squelch? JVE LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.RtcpHeaderException); } catch (CompoundPacket.CompoundPacketException e) { // TODO - this is a pretty serious error - what should we do - exit thread, squelch? JVE LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.CompoundPacketException); } catch (ThreadAbortException) {} catch (Exception e) { LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error); } } }