SocketSource.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_PPI_SocketSource_
18 #define HH_SENF_PPI_SocketSource_ 1
19 
20 // Custom includes
21 #include <senf/Packets/Packets.hh>
26 #include "Module.hh"
27 #include "Connectors.hh"
28 #include "IOEvent.hh"
29 
30 //#include "SocketSource.mpp"
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
32 
33 namespace senf {
34 namespace ppi {
35 
36 
38  {
40  };
41 
42  std::ostream & operator<<(std::ostream & os, ReadTimestamp const & annotation);
43 
51  template <class Packet=DataPacket, unsigned MaxSize=0u>
53  {
54  public:
55  typedef Packet PacketType;
60 
61  Packet operator()(Handle & handle);
63 
68  };
69 
70 }}
71 
72 namespace senf {
73 namespace ppi {
74 namespace module {
75 
107  template <class Reader=DgramReader<> >
109  : public Module
110  {
112 
113  public:
114  typedef typename Reader::Handle Handle;
115 
118 
119  ActiveSocketSource(unsigned max_burst=1);
120  explicit ActiveSocketSource(Reader reader, unsigned max_burst=1);
121  explicit ActiveSocketSource(Handle const & handle, unsigned max_burst=1);
122  ActiveSocketSource(Handle const & handle, Reader reader, unsigned max_burst=1);
123 
124  Reader & reader();
125  Handle handle();
126  void handle(Handle const & handle);
128 
131  unsigned maxBurst() const;
132  void maxBurst(unsigned max_burst);
133 
134  void flush();
135 
136  struct RxStats {
137  RxStats () {
138  clear();
139  }
140  void clear() {
141  memset(this, 0, sizeof(*this));
142  }
143  void dump(std::ostream & os) const {
144  os << "received " << received << ", "
145  << "noop " << noop << ".";
146  }
147 
148  unsigned received;
149  unsigned noop;
150  };
151 
153  return rxStats_;
154  }
155 
156  private:
157  Handle handle_;
158  IOEvent event_;
159  Reader reader_;
160  unsigned maxBurst_;
161  unsigned burst_;
162  bool flush_pending_;
163  RxStats rxStats_;
164  void read();
165  };
166 
167 }}}
168 
169 //-/////////////////////////////////////////////////////////////////////////////////////////////////
170 #include "SocketSource.cci"
171 #include "SocketSource.ct"
172 #include "SocketSource.cti"
173 #endif
174 
175 
176 // Local Variables:
177 // mode: c++
178 // fill-column: 100
179 // c-file-style: "senf"
180 // indent-tabs-mode: nil
181 // ispell-local-dictionary: "american"
182 // compile-command: "scons -u test"
183 // comment-column: 40
184 // End:
config::time_type clock_type
IOEvent public header.
Module base-class.
Definition: Module.hh:169
Connectors public header.
Module public header.
senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::ReadablePolicy, senf::DatagramFramingPolicy >::policy > Handle
Handle type supported by this reader.
Definition: SocketSource.hh:58
std::ostream & operator<<(std::ostream &os, QueueBufferAnnotation const &annotation)
ClockService::clock_type value
Definition: SocketSource.hh:39
#define SENF_PPI_MODULE(name)
Define PPI Module.
Definition: Module.hh:346
FileHandle based I/O read/write event.
Definition: IOEvent.hh:61
Reader::Handle Handle
Handle type requested by the reader.
connector::ActiveOutput< typename Reader::PacketType > output
Output connector to which the data received is written.
::phoenix::function< detail::clear > const clear
Reader for module::ActiveSocketSource.
Definition: SocketSource.hh:52
Input module reading data from an arbitrary FileHandle.