Scheduler: Update ReadHelper/WriteHelper to ne Socket API
g0dil [Fri, 29 Jun 2007 14:11:13 +0000 (14:11 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@279 270642c3-0616-0410-b53a-bc976706d245

Scheduler/ReadHelper.ct
Scheduler/WriteHelper.ct
Scheduler/WriteHelper.hh

index 40ac199..687a540 100644 (file)
@@ -72,7 +72,8 @@ prefix_ void senf::ReadHelper<Handle>::process(Handle handle,
     try {
         if (event != senf::Scheduler::EV_READ)
             throw SystemException(EPIPE);
-        std::string rcv (handle.read(maxSize_ - data_.size()));
+        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) {
index 9dfa747..6af5af8 100644 (file)
@@ -35,7 +35,7 @@ template <class Handle>
 prefix_ senf::WriteHelper<Handle>::WriteHelper(Handle handle, std::string data,
                                                       Callback callback)
     : handle_(handle), data_(data), callback_(callback),
-      offset_(0), errno_(0)
+      offset_(data_.begin()), errno_(0)
 {
     senf::Scheduler::instance()
         .add(handle_, boost::bind(&WriteHelper::dispatchProcess, ptr(this), _1, _2),
@@ -46,9 +46,9 @@ template <class Handle>
 prefix_ std::string const & senf::WriteHelper<Handle>::data()
     const
 {
-    if (offset_ > 0) {
-        data_.erase(0,offset_);
-        offset_ = 0;
+    if (offset_ > data_.begin()) {
+        data_.erase(data_.begin(),offset_);
+        offset_ = data_.begin();
     }
     return data_;
 }
@@ -79,9 +79,10 @@ prefix_ void senf::WriteHelper<Handle>::process(Handle handle,
     try {
         if (event != senf::Scheduler::EV_WRITE)
             throw senf::SystemException(EPIPE);
-        offset_ += handle.write(data_.data()+offset_,data_.size()-offset_);
-        if (offset_ >= data_.size()) {
+        offset_ = handle.write(std::make_pair(offset_,data_.end()));
+        if (offset_ == data_.end()) {
             data_.erase();
+            offset_ = data_.begin();
             complete_ = true;
         }
     }
index ccc2d26..7b4f0b4 100644 (file)
@@ -105,7 +105,7 @@ namespace senf {
         mutable std::string data_;
         Callback callback_;
 
-        mutable std::string::size_type offset_;
+        mutable std::string::iterator offset_;
         int errno_;
     };