Пример #1
0
 public void SetSourceEvents(XmlRpcSource source, EventType eventMask)
 {
     foreach (var record in sources.Where(x => x.Client == source))
     {
         record.Mask |= eventMask;
     }
 }
Пример #2
0
 public void RemoveSource(XmlRpcSource source)
 {
     lock (sources)
     {
         sources.RemoveAll(x => x.Client == source);
     }
 }
Пример #3
0
 public void AddSource(XmlRpcSource source, EventType eventMask)
 {
     lock (sources)
     {
         sources.Add(new DispatchRecord {
             Client = source, Mask = eventMask
         });
     }
 }
Пример #4
0
        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;
                }
            }
        }
Пример #5
0
        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;
                }
            }
        }