Inheritance: IDisposable
Example #1
0
 public void AddSource(XmlRpcSource source, EventType eventMask)
 {
     sources.Add(new DispatchRecord {
         client = source, mask = eventMask
     });
     //addsource(instance, source.instance, (uint) eventMask);
 }
Example #2
0
 public void SetSourceEvents(XmlRpcSource source, EventType eventMask)
 {
     foreach (var record in sources)
     {
         if (record.client == source)
         {
             record.mask |= eventMask;
         }
     }
 }
Example #3
0
 public void SetSourceEvents(XmlRpcSource source, EventType eventMask)
 {
     foreach (var record in sources)
     {
         if (record.client == source)
         {
             record.mask |= eventMask;
         }
     }
 }
Example #4
0
 public void RemoveSource(XmlRpcSource source)
 {
     foreach (var record in sources)
     {
         if (record.client == source)
         {
             sources.Remove(record);
             break;
         }
     }
 }
Example #5
0
 public void RemoveSource(XmlRpcSource source)
 {
     foreach (var record in sources)
     {
         if (record.client == source)
         {
             sources.Remove(record);
             break;
         }
     }
 }
Example #6
0
 public void AddSource(XmlRpcSource source, EventType eventMask)
 {
     sources.Add(new DispatchRecord { client = source, mask = eventMask });
     //addsource(instance, source.instance, (uint) eventMask);
 }
Example #7
0
        private void CheckSources(IEnumerable <DispatchRecord> sources, double timeout, List <XmlRpcSource> toRemove)
        {
            EventType defaultMask = EventType.ReadableEvent | EventType.WritableEvent | EventType.Exception;

            ArrayList checkRead  = new ArrayList();
            ArrayList checkWrite = new ArrayList();
            ArrayList checkExc   = new ArrayList();

            foreach (var src in sources)
            {
                Socket sock = src.client.getSocket();
                if (sock == null)
                {
                    continue;
                }
                var mask = src.mask;
                if ((mask & EventType.ReadableEvent) != 0)
                {
                    checkRead.Add(sock); // FD_SET(fd, &inFd);
                }
                if ((mask & EventType.WritableEvent) != 0)
                {
                    checkWrite.Add(sock);
                }
                //FD_SET(fd, &outFd);
                if ((mask & EventType.Exception) != 0)
                {
                    checkExc.Add(sock);
                }
            }

            // Check for events

            if (timeout < 0.0)
            {
                Socket.Select(checkRead, checkWrite, checkExc, -1);
            }
            else
            {
                //struct timeval tv;
                //tv.tv_sec = (int)floor(timeout);
                //tv.tv_usec = ((int)floor(1000000.0 * (timeout-floor(timeout)))) % 1000000;
                Socket.Select(checkRead, checkWrite, checkExc, (int)(timeout * 1000000.0));
                //nEvents = select(maxFd+1, &inFd, &outFd, &excFd, &tv);
            }

            int nEvents = checkRead.Count + checkWrite.Count + checkExc.Count;

            if (nEvents == 0)
            {
                return;
            }

            // Process events
            foreach (var record in sources)
            {
                XmlRpcSource src     = record.client;
                EventType    newMask = defaultMask; // (unsigned) -1;
                Socket       sock    = src.getSocket();
                if (sock == null)
                {
                    continue; // Seems like this is serious error
                }
                // 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 (checkExc.Contains(sock))
                {
                    newMask &= src.HandleEvent(EventType.Exception);
                }

                // Find the source again.  It may have moved as a result of the way
                // that sources are removed and added in the call stack starting
                // from the handleEvent() calls above.

                /*
                 * for (thisIt=_sources.begin(); thisIt != _sources.end(); thisIt++)
                 * {
                 *  if(thisIt->getSource() == src)
                 *  break;
                 * }
                 * if(thisIt == _sources.end())
                 * {
                 *  XmlRpcUtil::error("Error in XmlRpcDispatch::work: couldn't find source iterator");
                 *  continue;
                 * }*/

                if (newMask == EventType.NoEvent)
                {
                    //_sources.erase(thisIt);  // Stop monitoring this one
                    toRemove.Add(src);
                    // TODO: should we close it right here?
                    //this.RemoveSource(src);
                    //if (!src.getKeepOpen())
                    //    src.Close();
                }
                else if (newMask != defaultMask)
                {
                    record.mask = newMask;
                }
            }
        }