From: g0dil Date: Fri, 29 Jun 2007 14:11:13 +0000 (+0000) Subject: Scheduler: Update ReadHelper/WriteHelper to ne Socket API X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5ab3b3755f33d1d341ccca687810ceb818d09e95;p=senf.git Scheduler: Update ReadHelper/WriteHelper to ne Socket API git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@279 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/ReadHelper.ct b/Scheduler/ReadHelper.ct index 40ac199..687a540 100644 --- a/Scheduler/ReadHelper.ct +++ b/Scheduler/ReadHelper.ct @@ -72,7 +72,8 @@ prefix_ void senf::ReadHelper::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) { diff --git a/Scheduler/WriteHelper.ct b/Scheduler/WriteHelper.ct index 9dfa747..6af5af8 100644 --- a/Scheduler/WriteHelper.ct +++ b/Scheduler/WriteHelper.ct @@ -35,7 +35,7 @@ template prefix_ senf::WriteHelper::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 prefix_ std::string const & senf::WriteHelper::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::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; } } diff --git a/Scheduler/WriteHelper.hh b/Scheduler/WriteHelper.hh index ccc2d26..7b4f0b4 100644 --- a/Scheduler/WriteHelper.hh +++ b/Scheduler/WriteHelper.hh @@ -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_; };