SocketSink.ct
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 
14 /** \file
15  \brief SocketSink non-inline template implementation */
16 
17 //#include "SocketSink.ih"
18 
19 // Custom includes
20 
21 #define prefix_
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::ppi::module::ActiveSocketSink<Writer>
26 
27 template <class Writer>
28 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink()
29 {
30  registerEvent( event_, &ActiveSocketSink::write );
31  route(input, event_);
32 }
33 
34 template <class Writer>
35 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Writer const & writer)
36  : writer_ (writer)
37 {
38  registerEvent( event_, &ActiveSocketSink::write );
39  route(input, event_);
40 }
41 
42 template <class Writer>
43 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle const & handle)
44  : handle_(handle), event_(handle_, IOEvent::Write), writer_()
45 {
46  registerEvent( event_, &ActiveSocketSink::write );
47  route(input, event_);
48 }
49 
50 template <class Writer>
51 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle const & handle,
52  Writer const & writer)
53  : handle_(handle), event_(handle_, IOEvent::Write), writer_(writer)
54 {
55  registerEvent( event_, &ActiveSocketSink::write );
56  route(input, event_);
57 }
58 
59 //-/////////////////////////////////////////////////////////////////////////////////////////////////
60 // private members
61 
62 template <class Writer>
63 prefix_ void senf::ppi::module::ActiveSocketSink<Writer>::write()
64 {
65  writer_(handle_,input());
66 }
67 
68 //-/////////////////////////////////////////////////////////////////////////////////////////////////
69 // senf::ppi::module::PassiveSocketSink<Writer>
70 
71 template <class Writer>
72 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink()
73 {
74  noroute(input);
75  input.onRequest(&PassiveSocketSink::write);
76  checkThrottle();
77 }
78 
79 template <class Writer>
80 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Writer const & writer)
81  : writer_ (writer)
82 {
83  noroute(input);
84  input.onRequest(&PassiveSocketSink::write);
85  checkThrottle();
86 }
87 
88 template <class Writer>
89 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle const & handle)
90  : handle_(handle), writer_()
91 {
92  noroute(input);
93  input.onRequest(&PassiveSocketSink::write);
94  checkThrottle();
95 }
96 
97 template <class Writer>
98 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle const & handle,
99  Writer const & writer)
100  : handle_(handle), writer_(writer)
101 {
102  noroute(input);
103  input.onRequest(&PassiveSocketSink::write);
104  checkThrottle();
105 }
106 
107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
108 // private members
109 
110 template <class Writer>
111 prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::write()
112 {
113  if (writer_(handle_,input()))
114  txStats_.sent++;
115  else
116  txStats_.error++;
117 }
118 
119 template <class Writer>
120 prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::checkThrottle()
121 {
122  if (handle_.valid())
123  input.unthrottle();
124  else
125  input.throttle();
126 }
127 
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
129 #undef prefix_
130 
131 
132 // Local Variables:
133 // mode: c++
134 // fill-column: 100
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"
140 // End: