WriteHelper.hh
Go to the documentation of this file.
1 //
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
6 //
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
11 //
12 
13 
17 #ifndef HH_SENF_Scheduler_WriteHelper_
18 #define HH_SENF_Scheduler_WriteHelper_ 1
19 
20 // Custom includes
21 #include <string>
22 #include <boost/intrusive_ptr.hpp>
23 #include <boost/function.hpp>
25 #include "FdEvent.hh"
26 
27 //#include "WriteHelper.mpp"
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 namespace senf {
31 
46  template <class Handle>
49  {
50  public:
51  //-////////////////////////////////////////////////////////////////////////
52  // Types
53 
54  typedef boost::intrusive_ptr<WriteHelper> ptr;
55  typedef boost::function<void (ptr)> Callback;
56 
57  //-////////////////////////////////////////////////////////////////////////
59  //\{
60 
61  static ptr dispatch(Handle handle, std::string const & data, Callback callback);
63 
72  //\}
73  //-////////////////////////////////////////////////////////////////////////
74 
75  Handle handle() const;
76 
77  std::string const & data() const;
78 
82  bool complete() const;
83  bool error() const;
84  void throw_error() const;
85 
86  void revoke();
87 
88  protected:
89 
90  private:
91  WriteHelper(Handle handle, std::string const & data, Callback callback);
92 
93  static void dispatchProcess(ptr helper, Handle handle,
95  void process(Handle handle, senf::scheduler::FdEvent::Events event);
96  void done();
97 
98  Handle handle_;
99  scheduler::FdEvent fde_;
100  mutable std::string data_;
101  Callback callback_;
102 
103  mutable std::string::iterator offset_;
104  int errno_;
105  };
106 
107 
108 }
109 
110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 //#include "WriteHelper.cci"
112 #include "WriteHelper.ct"
113 #include "WriteHelper.cti"
114 //#include "WriteHelper.mpp"
115 #endif
116 
117 
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"
125 // comment-column: 40
126 // End:
Asynchronous writing helper.
Definition: WriteHelper.hh:47
bool complete() const
Check whether the write has completed successfully.
boost::intrusive_ptr< WriteHelper > ptr
Smart pointer type for this class.
Definition: WriteHelper.hh:54
boost::function< void(ptr)> Callback
Callback type.
Definition: WriteHelper.hh:55
File descriptor event.
Definition: FdEvent.hh:72
bool error() const
Check for error condition.
FdDispatcher public header.
void revoke()
Remove the WriteHelper from the scheduler.
void throw_error() const
If an error occurred, throw it.
Handle handle() const
static ptr dispatch(Handle handle, std::string const &data, Callback callback)
Register new WriteHelper instance.
std::string const & data() const
Return the data.