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 ProtocolServerSocketHandle inline template implementation
18 // Definition of inline template functions
20 //#include "ProtocolServerSocketHandle.ih"
23 #include <senf/Utils/senfassert.hh>
24 #include "ProtocolClientSocketHandle.hh"
26 #define prefix_ inline
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 template <class SocketProtocol>
30 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
31 ProtocolServerSocketHandle(senf::NoInit_t)
34 template <class SocketProtocol>
35 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::ProtocolServerSocketHandle()
36 : ServerSocketHandle<typename SocketProtocol::Policy>(
37 std::unique_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(true)))
40 #define BOOST_PP_ITERATION_PARAMS_1 \
41 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2))
42 #include BOOST_PP_ITERATE()
44 template <class SocketProtocol>
45 prefix_ SocketProtocol &
46 senf::ProtocolServerSocketHandle<SocketProtocol>::protocol()
48 SENF_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()),
49 "Internal failure: Incompatible protocol class fount it's way into this handle");
50 // Need dynamic_cast here, since senf::SocketProtocol is a
52 return dynamic_cast<SocketProtocol &>(this->body().protocol());
55 template <class SocketProtocol>
56 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
57 senf::ProtocolServerSocketHandle<SocketProtocol>::accept()
59 return ProtocolClientSocketHandle<SocketProtocol>(
60 FileHandle(this->ServerSocketHandle<typename SocketProtocol::Policy>::accept()),true);
63 template <class SocketProtocol>
64 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>
65 senf::ProtocolServerSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
67 return ProtocolServerSocketHandle(handle,true);
70 template <class SocketProtocol>
71 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>
72 senf::ProtocolServerSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
74 ServerSocketHandle<typename SocketProtocol::Policy> h (
75 ServerSocketHandle<typename SocketProtocol::Policy>::cast_dynamic(handle));
76 // throw std::bad_cast if the protocol is invalid
77 IGNORE( dynamic_cast<SocketProtocol const &>(static_cast<SocketBody&>(FileHandle::body(h)).protocol()) );
78 return cast_static(handle);
81 template <class SocketProtocol>
83 senf::ProtocolServerSocketHandle<SocketProtocol>::state(SocketStateMap & map,
86 map["handle"] = prettyName(typeid(*this));
88 map["valid"] << "true";
89 this->body().state(map,lod);
91 map["valid"] << "false";
94 template <class SocketProtocol>
96 senf::ProtocolServerSocketHandle<SocketProtocol>::dumpState(unsigned lod)
100 return detail::dumpState(map);
103 template <class SocketProtocol>
104 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
105 ProtocolServerSocketHandle(FileHandle other, bool isChecked)
106 : ServerSocketHandle<typename SocketProtocol::Policy>(other,isChecked)
109 //-/////////////////////////////////////////////////////////////////////////////////////////////////
116 // c-file-style: "senf"
117 // indent-tabs-mode: nil
118 // ispell-local-dictionary: "american"
119 // compile-command: "scons -u test"
120 // comment-column: 40