3 // Copyright (C) 2006 Stefan Bund <g0dil@berlios.de>
5 // The contents of this file are subject to the Fraunhofer FOKUS Public License
6 // Version 1.0 (the "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 // http://senf.berlios.de/license.html
10 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
11 // but modifies the Mozilla Public License Version 1.1.
12 // See the full license text for the amendments.
14 // Software distributed under the License is distributed on an "AS IS" basis,
15 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 // for the specific language governing rights and limitations under the License.
18 // The Original Code is Fraunhofer FOKUS code.
20 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
21 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
22 // All Rights Reserved.
28 \brief WriteHelper non-inline template implementation */
30 //#include "WriteHelper.ih"
33 #include <boost/bind.hpp>
34 #include <senf/Utils/Exception.hh>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 template <class Handle>
40 prefix_ senf::WriteHelper<Handle>::WriteHelper(Handle handle, std::string const & data,
43 fde_("WriteHelper", boost::bind(&WriteHelper::dispatchProcess, ptr(this), _1, _2),
44 handle, scheduler::FdEvent::EV_WRITE),
45 data_(data), callback_(callback), offset_(data_.begin()), errno_(0)
48 template <class Handle>
49 prefix_ std::string const & senf::WriteHelper<Handle>::data()
52 if (offset_ > data_.begin()) {
53 data_.erase(data_.begin(),offset_);
54 offset_ = data_.begin();
59 template <class Handle>
60 prefix_ void senf::WriteHelper<Handle>::revoke()
62 ptr guard (this); // To ensure, 'this' is deleted only after this method terminates ...
64 fde_.action(0); // To remove the smart pointer reference to this
67 template <class Handle>
68 prefix_ void senf::WriteHelper<Handle>::dispatchProcess(ptr helper, Handle handle,
69 scheduler::FdEvent::Events event)
71 // since we have a 'ptr' argument, the instance cannot be deleted
72 // before this method returns
73 helper->process(handle, event);
76 template <class Handle>
77 prefix_ void senf::WriteHelper<Handle>::process(Handle handle,
78 scheduler::FdEvent::Events event)
80 bool complete_ (false);
82 if (event != scheduler::FdEvent::EV_WRITE)
83 throw SystemException(EPIPE SENF_EXC_DEBUGINFO);
84 offset_ = handle.write(std::make_pair(offset_,data_.end()));
85 if (offset_ == data_.end()) {
87 offset_ = data_.begin();
91 catch (senf::SystemException const & ex) {
92 errno_ = ex.errorNumber();
100 template <class Handle>
101 prefix_ void senf::WriteHelper<Handle>::done()
104 callback_(ptr(this));
107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"
118 // comment-column: 40