00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024 #ifndef HH_SENF_Scheduler_WriteHelper_
00025 #define HH_SENF_Scheduler_WriteHelper_ 1
00026
00027
00028 #include <string>
00029 #include <boost/intrusive_ptr.hpp>
00030 #include <boost/function.hpp>
00031 #include <senf/Utils/intrusive_refcount.hh>
00032 #include "FdEvent.hh"
00033
00034
00035
00036
00037 namespace senf {
00038
00053 template <class Handle>
00054 class WriteHelper
00055 : public senf::intrusive_refcount
00056 {
00057 public:
00058
00059
00060
00061 typedef boost::intrusive_ptr<WriteHelper> ptr;
00062 typedef boost::function<void (ptr)> Callback;
00063
00064
00066
00067
00068 static ptr dispatch(Handle handle, std::string const & data, Callback callback);
00070
00079
00080
00081
00082 Handle handle() const;
00083
00084 std::string const & data() const;
00085
00089 bool complete() const;
00090 bool error() const;
00091 void throw_error() const;
00092
00093 void revoke();
00094
00095 protected:
00096
00097 private:
00098 WriteHelper(Handle handle, std::string const & data, Callback callback);
00099
00100 static void dispatchProcess(ptr helper, Handle handle,
00101 senf::scheduler::FdEvent::Events event);
00102 void process(Handle handle, senf::scheduler::FdEvent::Events event);
00103 void done();
00104
00105 Handle handle_;
00106 scheduler::FdEvent fde_;
00107 mutable std::string data_;
00108 Callback callback_;
00109
00110 mutable std::string::iterator offset_;
00111 int errno_;
00112 };
00113
00114
00115 }
00116
00117
00118
00119 #include "WriteHelper.ct"
00120 #include "WriteHelper.cti"
00121
00122 #endif
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133