Fresco/Prague/include/Prague/Sys FdSet.hh,1.8,1.9

Tobias Hunger <[email protected]> Sat, 01 Nov 2003 10:56:40 +0000
Newsgroups gmane.comp.video.fresco.cvs
Message-ID <[email protected]>
Update of /cvs/fresco/Fresco/Prague/include/Prague/Sys
In directory purcel:/tmp/cvs-serv30026/Prague/include/Prague/Sys

Modified Files:
	FdSet.hh 
Log Message:
* assert that the FDSet will never try to add/remove negative FDs
  (which will cause a coredump)
* Fix calculation of max. FD in clear()


Index: FdSet.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/FdSet.hh,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- FdSet.hh	31 Oct 2003 22:33:10 -0000	1.8
+++ FdSet.hh	1 Nov 2003 10:56:37 -0000	1.9
@@ -41,11 +41,21 @@
       ~FdSet() { }
       FdSet &operator = (const FdSet &F) { my_fds = F.my_fds; my_m = F.my_m; return *this; }
       //. Add a fd to the set
-      void set(int fd) { FD_SET(fd, &my_fds); if (fd > my_m) my_m = fd; }
+      void set(int fd) { assert(fd >= 0); FD_SET(fd, &my_fds); if (fd > my_m) my_m = fd; }
       //. return whether the given fd is available for non-blocking i/o
-      bool isset(int fd) const { return FD_ISSET(fd, &my_fds); }
+      bool isset(int fd) const { assert(fd >= 0); return FD_ISSET(fd, &my_fds); }
       //. clear fd from the set
-      void clear(int fd) { FD_CLR(fd, &my_fds); if (fd == my_m) for (int i = 0; i < fd - 1; i++) if (isset(fd)) my_m = fd; }
+      void clear(int fd)
+      {
+          FD_CLR(fd, &my_fds);
+          if (fd == my_m)
+              for (int i = fd - 1; i >= 0; --i)
+                  if (isset(i))
+                  {
+                      my_m = i;
+                      break;
+                  }
+      }
       //. return max fd
       int max() const { return my_m; }
       operator fd_set *() { return &my_fds; }