3 // Copyright (C) 2006 Stefan Bund <g0dil@berlios.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the
17 // Free Software Foundation, Inc.,
18 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief WriteHelper non-inline template implementation */
24 //#include "WriteHelper.ih"
28 #include "Utils/Exception.hh"
29 #include "Scheduler.hh"
32 ///////////////////////////////ct.p////////////////////////////////////////
34 template <class Handle>
35 prefix_ senf::WriteHelper<Handle>::WriteHelper(Handle handle, std::string data,
37 : handle_(handle), data_(data), callback_(callback),
40 senf::Scheduler::instance()
41 .add(handle_, boost::bind(&WriteHelper::dispatchProcess, ptr(this), _1, _2),
42 senf::Scheduler::EV_WRITE);
45 template <class Handle>
46 prefix_ std::string const & senf::WriteHelper<Handle>::data()
50 data_.erase(0,offset_);
56 template <class Handle>
57 prefix_ void senf::WriteHelper<Handle>::revoke()
59 ptr guard (this); // To ensure, 'this' is deleted only after this method terminates ...
60 senf::Scheduler::instance()
61 .remove(handle_, senf::Scheduler::EV_WRITE);
64 template <class Handle>
66 senf::WriteHelper<Handle>::dispatchProcess(ptr helper, Handle handle,
67 senf::Scheduler::EventId event)
69 // since we have a 'ptr' argument, the instance cannot be deleted
70 // before this method returns
71 return helper->process(handle,event);
74 template <class Handle>
75 prefix_ void senf::WriteHelper<Handle>::process(Handle handle,
76 senf::Scheduler::EventId event)
78 /** \fixme Move the done() calls to outside the try/catch block */
80 if (event != senf::Scheduler::EV_WRITE)
81 throw senf::SystemException(EPIPE);
82 offset_ += handle.write(data_.data()+offset_,data_.size()-offset_);
83 if (offset_ >= data_.size()) {
88 catch (senf::SystemException const & ex) {
94 template <class Handle>
95 prefix_ void senf::WriteHelper<Handle>::done()
101 ///////////////////////////////ct.e////////////////////////////////////////