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 Daemon internal header */
17 #ifndef IH_SENF_Utils_Daemon_Daemon_
18 #define IH_SENF_Utils_Daemon_Daemon_ 1
22 #include <boost/intrusive/list.hpp>
23 #include <boost/intrusive/list_hook.hpp>
24 #include <boost/noncopyable.hpp>
25 #include <boost/function.hpp>
26 #include <senf/Scheduler/Scheduler.hh>
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 /** \brief Internal: Watch daemon process for successful startup */
39 DaemonWatcher(int pid, int coutpipe, int cerrpipe, int stdout, int stderr);
48 typedef boost::function<void ()> Callback;
50 Forwarder(int src, Callback cb);
53 void addTarget(int fd);
57 // This is awkward ... we'll need to erase an element from the target list given
58 // only the target object. This is best implement using an intrusive container.
59 // However, this makes memory-management explicit and we'll need to be careful.
60 typedef std::deque<char> Buffer;
62 typedef boost::intrusive::list_base_hook< boost::intrusive::tag<TargetListTag> > TargetListBase;
64 struct Target : public TargetListBase
66 Target(Forwarder & fwd, int fd);
69 Buffer::size_type offset;
70 scheduler::FdEvent writeevent;
73 typedef boost::intrusive::list< Target,
74 boost::intrusive::constant_time_size<false>,
75 boost::intrusive::base_hook<TargetListBase> > Targets;
80 void operator()(T * t) { delete t; }
83 void readData(int event);
84 void writeData(int event, Target * target);
90 scheduler::FdEvent readevent_;
93 void pipeClosed(int id);
94 void sigChld(siginfo_t const &);
105 scheduler::SignalEvent cldSignal_;
106 scheduler::TimerEvent timer_;
107 Forwarder coutForwarder_;
108 Forwarder cerrForwarder_;
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
120 // comment-column: 40
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"