2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief WriteHelper non-inline template implementation */
17 //#include "WriteHelper.ih"
20 #include <boost/bind.hpp>
21 #include <senf/Utils/Exception.hh>
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 template <class Handle>
27 prefix_ senf::WriteHelper<Handle>::WriteHelper(Handle handle, std::string const & data,
30 fde_("WriteHelper", boost::bind(&WriteHelper::dispatchProcess, ptr(this), _1, _2),
31 handle, scheduler::FdEvent::EV_WRITE),
32 data_(data), callback_(callback), offset_(data_.begin()), errno_(0)
35 template <class Handle>
36 prefix_ std::string const & senf::WriteHelper<Handle>::data()
39 if (offset_ > data_.begin()) {
40 data_.erase(data_.begin(),offset_);
41 offset_ = data_.begin();
46 template <class Handle>
47 prefix_ void senf::WriteHelper<Handle>::revoke()
49 ptr guard (this); // To ensure, 'this' is deleted only after this method terminates ...
51 fde_.action(0); // To remove the smart pointer reference to this
54 template <class Handle>
55 prefix_ void senf::WriteHelper<Handle>::dispatchProcess(ptr helper, Handle handle,
56 scheduler::FdEvent::Events event)
58 // since we have a 'ptr' argument, the instance cannot be deleted
59 // before this method returns
60 helper->process(handle, event);
63 template <class Handle>
64 prefix_ void senf::WriteHelper<Handle>::process(Handle handle,
65 scheduler::FdEvent::Events event)
67 bool complete_ (false);
69 if (event != scheduler::FdEvent::EV_WRITE)
70 throw SystemException(EPIPE SENF_EXC_DEBUGINFO);
71 offset_ = handle.write(std::make_pair(offset_,data_.end()));
72 if (offset_ == data_.end()) {
74 offset_ = data_.begin();
78 catch (senf::SystemException const & ex) {
79 errno_ = ex.errorNumber();
87 template <class Handle>
88 prefix_ void senf::WriteHelper<Handle>::done()
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40