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 ServerSocketHandle inline template implementation
18 // Definition of inline template functions
20 //#include "ServerSocketHandle.ih"
25 #define prefix_ inline
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 template <class SPolicy>
29 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle()
32 template <class SPolicy>
33 template <class OtherPolicy>
34 prefix_ senf::ServerSocketHandle<SPolicy>::
35 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
36 typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type *)
37 : SocketHandle<SPolicy>(other,true)
40 template <class SPolicy>
41 prefix_ senf::ServerSocketHandle<SPolicy>::
42 ServerSocketHandle(std::unique_ptr<SocketBody> body)
43 : SocketHandle<SPolicy>(std::move(body))
46 template <class SPolicy>
47 template <class OtherPolicy>
48 prefix_ typename senf::SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const &
49 senf::ServerSocketHandle<SPolicy>::operator=(ServerSocketHandle<OtherPolicy> other)
55 //-/////////////////////////////////////////////////////////////////////////////////////////////////
56 // Server socket interface
58 template <class SPolicy>
59 prefix_ void senf::ServerSocketHandle<SPolicy>::bind(AddressParam addr)
61 SPolicy::AddressingPolicy::bind(*this,addr);
64 template <class SPolicy>
65 prefix_ void senf::ServerSocketHandle<SPolicy>::listen(unsigned backlog)
67 SPolicy::CommunicationPolicy::listen(*this,backlog);
70 template <class SPolicy>
71 prefix_ typename senf::ServerSocketHandle<SPolicy>::Address
72 senf::ServerSocketHandle<SPolicy>::local()
74 typename SPolicy::AddressingPolicy::Address addr;
79 template <class SPolicy>
80 prefix_ void senf::ServerSocketHandle<SPolicy>::local(Address & addr)
82 SPolicy::AddressingPolicy::local(*this,addr);
85 template <class SPolicy>
86 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientHandle
87 senf::ServerSocketHandle<SPolicy>::accept()
89 return ClientHandle(this->body().clone(
90 SPolicy::CommunicationPolicy::accept(*this), false));
93 template <class SPolicy>
94 prefix_ std::pair<typename senf::ServerSocketHandle<SPolicy>::ClientHandle,
95 typename senf::ServerSocketHandle<SPolicy>::Address>
96 senf::ServerSocketHandle<SPolicy>::acceptfrom()
100 ClientHandle handle = acceptfrom(address);
101 return std::make_pair(handle,address);
104 template <class SPolicy>
105 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientHandle
106 senf::ServerSocketHandle<SPolicy>::acceptfrom(Address & addr)
108 return ClientHandle(this->body().clone(
109 SPolicy::CommunicationPolicy::accept(*this,addr), false));
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
114 template <class SPolicy>
115 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle(FileHandle other,
117 : SocketHandle<SPolicy>(other, isChecked)
120 template <class SPolicy>
121 prefix_ senf::ServerSocketHandle<SPolicy>
122 senf::ServerSocketHandle<SPolicy>::cast_static(FileHandle handle)
124 return ServerSocketHandle(handle,true);
127 template <class SPolicy>
128 prefix_ senf::ServerSocketHandle<SPolicy>
129 senf::ServerSocketHandle<SPolicy>::cast_dynamic(FileHandle handle)
131 SocketHandle<SPolicy> h (SocketHandle<SPolicy>::cast_dynamic(handle));
132 if (! static_cast<SocketBody&>(FileHandle::body(handle)).isServer())
133 throw std::bad_cast();
134 return cast_static(handle);
137 template <class SPolicy>
138 prefix_ void senf::ServerSocketHandle<SPolicy>::state(SocketStateMap & map, unsigned lod)
140 map["handle"] = prettyName(typeid(*this));
142 map["valid"] << "true";
143 this->body().state(map,lod);
145 map["valid"] << "false";
148 template <class SPolicy>
149 prefix_ std::string senf::ServerSocketHandle<SPolicy>::dumpState(unsigned lod)
153 return detail::dumpState(map);
156 //-/////////////////////////////////////////////////////////////////////////////////////////////////
163 // c-file-style: "senf"
164 // indent-tabs-mode: nil
165 // ispell-local-dictionary: "american"
166 // compile-command: "scons -u test"
167 // comment-column: 40