fixed some file headers to the new format
[senf.git] / Scheduler / Scheduler.cc
index 4170851..96aa9a2 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS) 
+// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -58,24 +58,24 @@ prefix_ senf::Scheduler::Scheduler()
       eventTime_(0), eventEarly_(ClockService::milliseconds(11)), eventAdjust_(0)
 {
     if (epollFd_<0)
-        throw SystemException(errno);
+        throwErrno();
 
     if (::pipe(sigpipe_) < 0)
-        throw SystemException(errno);
+        throwErrno();
 
     int flags (::fcntl(sigpipe_[1],F_GETFL));
     if (flags < 0) 
-        throw SystemException(errno);
+        throwErrno();
     flags |= O_NONBLOCK;
     if (::fcntl(sigpipe_[1], F_SETFL, flags) < 0) 
-        throw SystemException(errno);
+        throwErrno();
 
     ::epoll_event ev;
     ::memset(&ev, 0, sizeof(ev));
     ev.events = EV_READ;
     ev.data.fd = sigpipe_[0];
     if (::epoll_ctl(epollFd_, EPOLL_CTL_ADD, sigpipe_[0], &ev) < 0)
-        throw SystemException(errno);
+        throwErrno();
 }
 
 prefix_ void senf::Scheduler::registerSignal(unsigned signal, SimpleCallback const & cb)
@@ -104,12 +104,20 @@ prefix_ void senf::Scheduler::unregisterSignal(unsigned signal)
 
 prefix_ void senf::Scheduler::do_add(int fd, FdCallback const & cb, int eventMask)
 {
+    if (eventMask == 0)
+        return;
+
     FdTable::iterator i (fdTable_.find(fd));
     int action (EPOLL_CTL_MOD);
     if (i == fdTable_.end()) {
         action = EPOLL_CTL_ADD;
         i = fdTable_.insert(std::make_pair(fd, EventSpec())).first;
     }
+    if (i->second.epollMask() == 0) {
+        action = EPOLL_CTL_ADD;
+        fdErase_.erase( std::remove(fdErase_.begin(), fdErase_.end(), unsigned(fd)),
+                        fdErase_.end() );
+    }
 
     if (eventMask & EV_READ)  i->second.cb_read = cb;
     if (eventMask & EV_PRIO)  i->second.cb_prio = cb;
@@ -133,6 +141,9 @@ prefix_ void senf::Scheduler::do_add(int fd, FdCallback const & cb, int eventMas
 
 prefix_ void senf::Scheduler::do_remove(int fd, int eventMask)
 {
+    if (eventMask == 0)
+        return;
+
     FdTable::iterator i (fdTable_.find(fd));
     if (i == fdTable_.end())
         return;
@@ -170,7 +181,7 @@ prefix_ void senf::Scheduler::registerSigHandlers()
             if (signal == SIGCHLD)
                 sa.sa_flags |= SA_NOCLDSTOP;
             if (::sigaction(signal, &sa, 0) < 0)
-                throw SystemException(errno);
+                throwErrno();
         }
     }
 }
@@ -243,7 +254,7 @@ prefix_ void senf::Scheduler::process()
 
         if (events<0)
             if (errno != EINTR)
-                throw SystemException(errno);
+                throwErrno();
 
         eventTime_ = ClockService::now();