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_ReadHelper_
00025 #define HH_SENF_Scheduler_ReadHelper_ 1
00026
00027
00028 #include <string>
00029 #include <boost/function.hpp>
00030 #include <boost/intrusive_ptr.hpp>
00031 #include <boost/scoped_ptr.hpp>
00032
00033 #include <senf/Utils/intrusive_refcount.hh>
00034 #include "FdEvent.hh"
00035
00036
00037
00038
00039 namespace senf {
00040
00041
00068 template <class Handle>
00069 class ReadHelper
00070 : public senf::intrusive_refcount
00071 {
00072 public:
00073
00074
00075
00076 typedef boost::intrusive_ptr<ReadHelper> ptr;
00077 typedef boost::function<void (ptr)> Callback;
00078
00079
00081
00082
00083 static ptr dispatch(Handle handle, std::string::size_type maxSize,
00084 Callback callback);
00085
00096 template <class Predicate>
00097 static ptr dispatch(Handle handle, std::string::size_type maxSize, Predicate const & predicate,
00098 Callback callback);
00099
00112
00113
00114
00115 Handle handle() const;
00116 std::string::size_type maxSize() const;
00117
00118 std::string const & data() const;
00119 std::string const & tail() const;
00120
00121 bool complete() const;
00122 bool error() const;
00123 void throw_error() const;
00124
00125 void revoke();
00126
00127 protected:
00128
00129 private:
00130 struct InternalPredicate;
00131
00132 ReadHelper(Handle handle, std::string::size_type maxSize,
00133 InternalPredicate * predicate, Callback cb);
00134
00135 static void dispatchProcess(ptr helper, Handle handle, int event);
00136 void process(Handle handle, int event);
00137 void done();
00138
00139 Handle handle_;
00140 scheduler::FdEvent fde_;
00141 std::string::size_type maxSize_;
00142 boost::scoped_ptr<InternalPredicate> predicate_;
00143 Callback callback_;
00144
00145 std::string data_;
00146 std::string tail_;
00147 int errno_;
00148 bool complete_;
00149 };
00150
00159 struct ReadUntil
00160 {
00161 ReadUntil(std::string const & target);
00162 std::string::size_type operator()(std::string const & data);
00163 std::string target;
00164 };
00165
00166 }
00167
00168
00169 #include "ReadHelper.cci"
00170 #include "ReadHelper.ct"
00171 #include "ReadHelper.cti"
00172
00173 #endif
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184