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"
27 #include <boost/bind.hpp>
28 #include <senf/Utils/Exception.hh>
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 template <class Handle>
34 prefix_ senf::WriteHelper<Handle>::WriteHelper(Handle handle, std::string const & data,
37 fde_("WriteHelper", boost::bind(&WriteHelper::dispatchProcess, ptr(this), _1, _2),
38 handle, scheduler::FdEvent::EV_WRITE),
39 data_(data), callback_(callback), offset_(data_.begin()), errno_(0)
42 template <class Handle>
43 prefix_ std::string const & senf::WriteHelper<Handle>::data()
46 if (offset_ > data_.begin()) {
47 data_.erase(data_.begin(),offset_);
48 offset_ = data_.begin();
53 template <class Handle>
54 prefix_ void senf::WriteHelper<Handle>::revoke()
56 ptr guard (this); // To ensure, 'this' is deleted only after this method terminates ...
58 fde_.action(0); // To remove the smart pointer reference to this
61 template <class Handle>
62 prefix_ void senf::WriteHelper<Handle>::dispatchProcess(ptr helper, Handle handle,
63 scheduler::FdEvent::Events event)
65 // since we have a 'ptr' argument, the instance cannot be deleted
66 // before this method returns
67 helper->process(handle, event);
70 template <class Handle>
71 prefix_ void senf::WriteHelper<Handle>::process(Handle handle,
72 scheduler::FdEvent::Events event)
74 bool complete_ (false);
76 if (event != scheduler::FdEvent::EV_WRITE)
77 throw SystemException(EPIPE SENF_EXC_DEBUGINFO);
78 offset_ = handle.write(std::make_pair(offset_,data_.end()));
79 if (offset_ == data_.end()) {
81 offset_ = data_.begin();
85 catch (senf::SystemException const & ex) {
86 errno_ = ex.errorNumber();
94 template <class Handle>
95 prefix_ void senf::WriteHelper<Handle>::done()
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"
112 // comment-column: 40