4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ServerSocketHandle inline template implementation
32 // Definition of inline template functions
34 //#include "ServerSocketHandle.ih"
39 #define prefix_ inline
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 template <class SPolicy>
43 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle()
46 template <class SPolicy>
47 template <class OtherPolicy>
48 prefix_ senf::ServerSocketHandle<SPolicy>::
49 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
50 typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type *)
51 : SocketHandle<SPolicy>(other,true)
54 template <class SPolicy>
55 prefix_ senf::ServerSocketHandle<SPolicy>::
56 ServerSocketHandle(std::auto_ptr<SocketBody> body)
57 : SocketHandle<SPolicy>(body)
60 template <class SPolicy>
61 template <class OtherPolicy>
62 prefix_ typename senf::SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const &
63 senf::ServerSocketHandle<SPolicy>::operator=(ServerSocketHandle<OtherPolicy> other)
69 //-/////////////////////////////////////////////////////////////////////////////////////////////////
70 // Server socket interface
72 template <class SPolicy>
73 prefix_ void senf::ServerSocketHandle<SPolicy>::bind(AddressParam addr)
75 SPolicy::AddressingPolicy::bind(*this,addr);
78 template <class SPolicy>
79 prefix_ void senf::ServerSocketHandle<SPolicy>::listen(unsigned backlog)
81 SPolicy::CommunicationPolicy::listen(*this,backlog);
84 template <class SPolicy>
85 prefix_ typename senf::ServerSocketHandle<SPolicy>::Address
86 senf::ServerSocketHandle<SPolicy>::local()
88 typename SPolicy::AddressingPolicy::Address addr;
93 template <class SPolicy>
94 prefix_ void senf::ServerSocketHandle<SPolicy>::local(Address & addr)
96 SPolicy::AddressingPolicy::local(*this,addr);
99 template <class SPolicy>
100 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientHandle
101 senf::ServerSocketHandle<SPolicy>::accept()
103 return ClientHandle(this->body().clone(
104 SPolicy::CommunicationPolicy::accept(*this), false));
107 template <class SPolicy>
108 prefix_ std::pair<typename senf::ServerSocketHandle<SPolicy>::ClientHandle,
109 typename senf::ServerSocketHandle<SPolicy>::Address>
110 senf::ServerSocketHandle<SPolicy>::acceptfrom()
114 ClientHandle handle = acceptfrom(address);
115 return std::make_pair(handle,address);
118 template <class SPolicy>
119 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientHandle
120 senf::ServerSocketHandle<SPolicy>::acceptfrom(Address & addr)
122 return ClientHandle(this->body().clone(
123 SPolicy::CommunicationPolicy::accept(*this,addr), false));
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
128 template <class SPolicy>
129 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle(FileHandle other,
131 : SocketHandle<SPolicy>(other, isChecked)
134 template <class SPolicy>
135 prefix_ senf::ServerSocketHandle<SPolicy>
136 senf::ServerSocketHandle<SPolicy>::cast_static(FileHandle handle)
138 return ServerSocketHandle(handle,true);
141 template <class SPolicy>
142 prefix_ senf::ServerSocketHandle<SPolicy>
143 senf::ServerSocketHandle<SPolicy>::cast_dynamic(FileHandle handle)
145 SocketHandle<SPolicy> h (SocketHandle<SPolicy>::cast_dynamic(handle));
146 if (! static_cast<SocketBody&>(FileHandle::body(handle)).isServer())
147 throw std::bad_cast();
148 return cast_static(handle);
151 template <class SPolicy>
152 prefix_ void senf::ServerSocketHandle<SPolicy>::state(SocketStateMap & map, unsigned lod)
154 map["handle"] = prettyName(typeid(*this));
156 map["valid"] << "true";
157 this->body().state(map,lod);
159 map["valid"] << "false";
162 template <class SPolicy>
163 prefix_ std::string senf::ServerSocketHandle<SPolicy>::dumpState(unsigned lod)
167 return detail::dumpState(map);
170 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // c-file-style: "senf"
178 // indent-tabs-mode: nil
179 // ispell-local-dictionary: "american"
180 // compile-command: "scons -u test"
181 // comment-column: 40