private void CheckSources(IEnumerable <DispatchRecord> sources, TimeSpan timeout, List <XmlRpcSource> toRemove) { const EventType ALL_EVENTS = EventType.ReadableEvent | EventType.WritableEvent | EventType.Exception; var checkRead = new List <Socket>(); var checkWrite = new List <Socket>(); var checkError = new List <Socket>(); foreach (var src in sources) { var sock = src.Client.Socket; if (sock == null) { continue; } var mask = src.Mask; if (mask.HasFlag(EventType.ReadableEvent)) { checkRead.Add(sock); } if (mask.HasFlag(EventType.WritableEvent)) { checkWrite.Add(sock); } if (mask.HasFlag(EventType.Exception)) { checkError.Add(sock); } } // Check for events Socket.Select(checkRead, checkWrite, checkError, (int)(timeout.Milliseconds * 1000.0)); if (checkRead.Count + checkWrite.Count + checkError.Count == 0) { return; } // Process events foreach (var record in sources) { XmlRpcSource src = record.Client; EventType newMask = ALL_EVENTS; Socket sock = src.Socket; if (sock == null) { continue; } // if you select on multiple event types this could be ambiguous if (checkRead.Contains(sock)) { newMask &= src.HandleEvent(EventType.ReadableEvent); } if (checkWrite.Contains(sock)) { newMask &= src.HandleEvent(EventType.WritableEvent); } if (checkError.Contains(sock)) { newMask &= src.HandleEvent(EventType.Exception); } if (newMask == EventType.NoEvent) { toRemove.Add(src); } else { record.Mask = newMask; } } }
private void CheckSources(IEnumerable <DispatchRecord> sources, TimeSpan timeout, List <XmlRpcSource> toRemove) { const EventType ALL_EVENTS = EventType.ReadableEvent | EventType.WritableEvent | EventType.Exception; checkRead.Clear(); checkWrite.Clear(); checkError.Clear(); //int a = 0, b = 0, c = 0, d = sources.Count(); foreach (var src in sources) { Socket sock = src.Client.getSocket(); if (sock == null) { continue; } //if (!sock.Connected) //continue; //bool isValidConnection = sock.Connected || (!sock.Connected && sock.LocalEndPoint.ToString().StartsWith("0.0.0.0")); //if (!isValidConnection) // continue; var mask = src.Mask; if (mask.HasFlag(EventType.ReadableEvent)) { checkRead.Add(sock); //a++; } if (mask.HasFlag(EventType.WritableEvent)) { checkWrite.Add(sock); //b++; } if (mask.HasFlag(EventType.Exception)) { checkError.Add(sock); //c++; } } // Check for events Socket.Select(checkRead, checkWrite, checkError, (int)(timeout.Milliseconds * 1000.0)); //Thread.Yield(); //Console.WriteLine($"{d} - {a} - {b} - {c}"); if (checkRead.Count + checkWrite.Count + checkError.Count == 0) { return; } // Process events foreach (var record in sources) { XmlRpcSource src = record.Client; EventType newMask = ALL_EVENTS; Socket sock = src.getSocket(); if (sock == null) { continue; } // if you select on multiple event types this could be ambiguous if (checkRead.Contains(sock)) { newMask &= src.HandleEvent(EventType.ReadableEvent); } if (checkWrite.Contains(sock)) { newMask &= src.HandleEvent(EventType.WritableEvent); } if (checkError.Contains(sock)) { newMask &= src.HandleEvent(EventType.Exception); } if (newMask == EventType.NoEvent) { toRemove.Add(src); } else { record.Mask = newMask; } } }