Scheduler: Implement PollTimerSource
g0dil [Tue, 3 Feb 2009 08:40:25 +0000 (08:40 +0000)]
Utils/Daemon: Fix DuplicateEventRegistration bug

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1091 270642c3-0616-0410-b53a-bc976706d245

Scheduler/Scheduler.test.cc
Scheduler/TimerSource.cc
Scheduler/TimerSource.hh
Utils/Daemon/Daemon.cc
Utils/Daemon/Daemon.test.cc
doclib/pkgdraw

index c8dc0b4..8d6a53f 100644 (file)
@@ -1,4 +1,3 @@
-
 // $Id$
 //
 // Copyright (C) 2006
@@ -318,7 +317,7 @@ BOOST_AUTO_UNIT_TEST(testScheduler)
         BOOST_CHECK_NO_THROW( senf::scheduler::process() ); 
     } 
 
-    BOOST_CHECK_EQUAL( eventCount, 8u );
+    BOOST_CHECK( eventCount >= 8u );
 
     ///////////////////////////////////////////////////////////////////////////
 
index 17d2de7..84048b0 100644 (file)
@@ -27,6 +27,7 @@
 //#include "TimerSource.ih"
 
 // Custom includes
+#include "FdEvent.hh"
 
 //#include "TimerSource.mpp"
 #define prefix_
@@ -146,6 +147,27 @@ prefix_ void senf::scheduler::detail::POSIXTimerSource::reschedule()
         SENF_THROW_SYSTEM_EXCEPTION("timer_settime()");
 }
 
+///////////////////////////////////////////////////////////////////////////
+// senf::scheduler::detail::PollTimerSource
+
+prefix_ void senf::scheduler::detail::PollTimerSource::timeout(ClockService::clock_type timeout)
+{
+    ClockService::clock_type now (ClockService::now());
+    int delay (ClockService::in_milliseconds(timeout-now)+1);
+    FileDispatcher::instance().timeout(delay<0?0:delay);
+}
+
+prefix_ void senf::scheduler::detail::PollTimerSource::notimeout()
+{
+    FileDispatcher::instance().timeout(-1);
+}
+
+prefix_ void senf::scheduler::detail::PollTimerSource::enable()
+{}
+
+prefix_ void senf::scheduler::detail::PollTimerSource::disable()
+{}
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "TimerSource.mpp"
index f17c6fc..ae45048 100644 (file)
@@ -86,7 +86,10 @@ namespace detail {
     {
     public:
         virtual void timeout(ClockService::clock_type timeout);
-        virtual void disableTimeout();
+        virtual void notimeout();
+
+        virtual void enable();
+        virtual void disable();
     };
 
     class TimerFDTimerSource
@@ -94,7 +97,10 @@ namespace detail {
     {
     public:
         virtual void timeout(ClockService::clock_type timeout);
-        virtual void disableTimeout();
+        virtual void notimeout();
+
+        virtual void enable();
+        virtual void disable();
     };
 
 }}}
index 6bd84ae..8cbf98f 100644 (file)
@@ -132,8 +132,11 @@ prefix_ void senf::Daemon::openLog()
                   << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout.";
         stdout_ = fd;
     }
-    if (stderrLog_ == stdoutLog_)
-        stderr_ = fd;
+    if (stderrLog_ == stdoutLog_) {
+        stderr_ = ::dup(fd);
+        if (stderr_ < 0)
+            SENF_THROW_SYSTEM_EXCEPTION("::dup()");
+    } 
     else if (! stderrLog_.empty()) {
         fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
         if (fd < 0)
@@ -307,6 +310,7 @@ senf::Daemon * senf::Daemon::instance_ (0);
 
 prefix_ void senf::Daemon::configure()
 {
+    // int i (not unsigned) since argc_ is int ...
     for (int i (1); i<argc_; ++i) {
         if (argv_[i] == std::string("--no-daemon"))
             daemonize(false);
index f3dfc1e..c814ffd 100644 (file)
@@ -65,11 +65,12 @@ namespace {
 
         void init() { 
             std::cout << "Running init()" << std::endl; 
+            std::cerr << "(stderr)" << std::endl;
         }
 
         void run() {
             std::cout << "Running run()" << std::endl; 
-            delay(1500);
+            delay(2000);
         }
     };
 
@@ -141,7 +142,7 @@ BOOST_AUTO_UNIT_TEST(testDaemon)
             ::kill(pid, SIGHUP);
     }
 
-    delay(1000);
+    delay(2000);
     BOOST_CHECK( ! boost::filesystem::exists("testDaemon.pid") );
     BOOST_CHECK( boost::filesystem::exists("testDaemon.log") );
     BOOST_CHECK( boost::filesystem::exists("testDaemon.log.1") );
@@ -149,7 +150,7 @@ BOOST_AUTO_UNIT_TEST(testDaemon)
     std::ifstream log ("testDaemon.log.1");
     std::stringstream data;
     data << log.rdbuf();
-    BOOST_CHECK_EQUAL( data.str(), "Running init()\nRunning run()\n" );
+    BOOST_CHECK_EQUAL( data.str(), "Running init()\n(stderr)\nRunning run()\n" );
     BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") );
     BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log.1") );
 }
index ecadad7..92e0f02 100755 (executable)
@@ -63,7 +63,7 @@ def formatSimpleField(width, start, field):
             namesz = areas[i]['size']
             nameix = i
     areas[nameix]['name'] = field['name'][:int(areas[nameix]['size'] * charsPerBit)]
-    if len(areas) == 2 and areas[0].get('bottom',True):
+    if field['name'] and len(areas) == 2 and areas[0].get('bottom',True):
         if areas[0].get('name','') : ix = 1
         else                       : ix = 0
         if 6 <= int(areas[ix]['size'] * charsPerBit):