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 SocketSource non-inline template implementation */
17 //#include "SocketSource.ih"
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::ppi::DgramReader<Packet,MaxSize>
27 template <class Packet, unsigned MaxSize>
28 prefix_ Packet senf::ppi::DgramReader<Packet,MaxSize>::operator()(Handle & handle)
30 Packet packet (Packet::create(senf::noinit));
31 handle.read(packet.data(), MaxSize);
32 #ifdef SENF_PPI_READ_TIMESTAMP
33 packet.template annotation<senf::ppi::ReadTimestamp>().value = senf::ClockService::now();
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::ppi::module::ActiveSocketSource<Reader>
41 template <class Reader>
42 prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(unsigned max_burst)
43 : maxBurst_(max_burst), burst_(0)
45 registerEvent( event_, &ActiveSocketSource::read );
46 route(event_, output);
49 template <class Reader>
50 prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Reader reader, unsigned max_burst)
51 : reader_(reader), maxBurst_(maxBurst), burst_(0)
53 registerEvent( event_, &ActiveSocketSource::read );
54 route(event_, output);
57 template <class Reader>
58 prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Handle const & handle, unsigned max_burst)
59 : handle_(handle), event_(handle_, IOEvent::Read), maxBurst_(max_burst), burst_(0)
61 registerEvent( event_, &ActiveSocketSource::read );
62 route(event_, output);
65 template <class Reader>
66 prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Handle const & handle,
67 Reader reader, unsigned max_burst)
68 : handle_(handle), event_(handle_, IOEvent::Read), reader_(reader), maxBurst_(max_burst), burst_(0)
70 registerEvent( event_, &ActiveSocketSource::read );
71 route(event_, output);
74 template <class Reader>
75 prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::maxBurst(unsigned max_burst)
77 maxBurst_ = max_burst;
80 template <class Reader>
81 prefix_ unsigned senf::ppi::module::ActiveSocketSource<Reader>::maxBurst()
87 template <class Reader>
88 prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::read()
90 flush_pending_ = false;
91 for (burst_ = 1; handle_ and !flush_pending_ and (burst_ <= maxBurst_); ++burst_) {
92 typename Reader::PacketType p (reader_(handle_));
93 if (SENF_LIKELY(p and (p.data().size() > 0))) {
105 if (flush_pending_) {
110 template <class Reader>
111 prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::flush()
117 flush_pending_ = true;
122 while (handle_ && handle_.readable() && reader_(handle_));
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 // comment-column: 40
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"