Utils/Console: Fix singleton instantiation order (ServerManager / Scheduler)
[senf.git] / Scheduler / ReadHelper.ct
index 3ac3df5..42d068a 100644 (file)
@@ -25,8 +25,8 @@
 
 // Custom includes
 #include <errno.h>
-#include "Utils/membind.hh"
-#include "Utils/Exception.hh"
+#include "../Utils/membind.hh"
+#include "../Utils/Exception.hh"
 #include "Scheduler.hh"
 
 #define prefix_
@@ -43,7 +43,7 @@ prefix_ senf::ReadHelper<Handle>::ReadHelper(Handle handle, std::string::size_ty
     // scheduler. This ensures, that the refcount is at least 1 as
     // long as the helper is registered with the scheduler.
     senf::Scheduler::instance()
-        .add(handle,boost::bind(&ReadHelper::dispatchProcess,ptr(this),_1,_2),
+        .add(handle,boost::bind(&ReadHelper::dispatchProcess,ptr(this), handle, _1),
              senf::Scheduler::EV_READ);
 }
 
@@ -57,8 +57,7 @@ prefix_ void senf::ReadHelper<Handle>::revoke()
 
 template <class Handle>
 prefix_ void
-senf::ReadHelper<Handle>::dispatchProcess(ptr helper, Handle handle,
-                                                 senf::Scheduler::EventId event)
+senf::ReadHelper<Handle>::dispatchProcess(ptr helper, Handle handle, int event)
 {
     // since we have a 'ptr' argument, the instance cannot be deleted
     // before this method returns
@@ -66,14 +65,13 @@ senf::ReadHelper<Handle>::dispatchProcess(ptr helper, Handle handle,
 }
 
 template <class Handle>
-prefix_ void senf::ReadHelper<Handle>::process(Handle handle,
-                                                      senf::Scheduler::EventId event)
+prefix_ void senf::ReadHelper<Handle>::process(Handle handle,int event)
 {
-    /** \fixme Move the done() calls to outside the try/catch block */
     try {
         if (event != senf::Scheduler::EV_READ)
-            throw SystemException(EPIPE);
-        std::string rcv (handle.read(maxSize_ - data_.size()));
+            throw SystemException(EPIPE SENF_EXC_DEBUGINFO);
+        std::string rcv;
+        handle.read(rcv, maxSize_ - data_.size());
         data_.append(rcv);
         std::string::size_type n = predicate_ ? (*predicate_)(data_) : std::string::npos;
         if (n != std::string::npos || data_.size() >= maxSize_ || rcv.size() == 0) {
@@ -82,13 +80,15 @@ prefix_ void senf::ReadHelper<Handle>::process(Handle handle,
                 tail_.assign(data_,n,std::string::npos);
                 data_.erase(n);
             }
-            done();
         }
     }
     catch (senf::SystemException const & ex) {
-        errno_ = ex.err;
+        errno_ = ex.errorNumber();
         done();
+        return;
     }
+    if (complete_)
+        done();
 }
 
 template <class Handle>
@@ -117,4 +117,6 @@ operator()(std::string const & data)
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: