4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief ServerSocketHandle inline template implementation
27 // Definition of inline template functions
29 //#include "ServerSocketHandle.ih"
34 #define prefix_ inline
35 ///////////////////////////////cti.p///////////////////////////////////////
37 template <class SPolicy>
38 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle()
41 template <class SPolicy>
42 template <class OtherPolicy>
43 prefix_ senf::ServerSocketHandle<SPolicy>::
44 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
45 typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type *)
46 : SocketHandle<SPolicy>(other,true)
49 template <class SPolicy>
50 prefix_ senf::ServerSocketHandle<SPolicy>::
51 ServerSocketHandle(std::auto_ptr<SocketBody> body)
52 : SocketHandle<SPolicy>(body)
55 template <class SPolicy>
56 template <class OtherPolicy>
57 prefix_ typename senf::SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const &
58 senf::ServerSocketHandle<SPolicy>::operator=(ServerSocketHandle<OtherPolicy> other)
64 ///////////////////////////////////////////////////////////////////////////
65 // Server socket interface
67 template <class SPolicy>
68 prefix_ void senf::ServerSocketHandle<SPolicy>::bind(AddressParam addr)
70 SPolicy::AddressingPolicy::bind(*this,addr);
73 template <class SPolicy>
74 prefix_ void senf::ServerSocketHandle<SPolicy>::listen(unsigned backlog)
76 SPolicy::CommunicationPolicy::listen(*this,backlog);
79 template <class SPolicy>
80 prefix_ typename senf::ServerSocketHandle<SPolicy>::Address
81 senf::ServerSocketHandle<SPolicy>::local()
83 typename SPolicy::AddressingPolicy::Address addr;
88 template <class SPolicy>
89 prefix_ void senf::ServerSocketHandle<SPolicy>::local(Address & addr)
91 SPolicy::AddressingPolicy::local(*this,addr);
94 template <class SPolicy>
95 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientSocketHandle
96 senf::ServerSocketHandle<SPolicy>::accept()
98 return ClientSocketHandle(this->body().clone(
99 SPolicy::CommunicationPolicy::accept(*this), false));
102 template <class SPolicy>
103 prefix_ std::pair<typename senf::ServerSocketHandle<SPolicy>::ClientSocketHandle,
104 typename senf::ServerSocketHandle<SPolicy>::Address>
105 senf::ServerSocketHandle<SPolicy>::acceptfrom()
109 ClientSocketHandle handle = acceptfrom(address);
110 return std::make_pair(handle,address);
113 template <class SPolicy>
114 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientSocketHandle
115 senf::ServerSocketHandle<SPolicy>::acceptfrom(Address & addr)
117 return ClientSocketHandle(this->protocol().clone(),
118 SPolicy::CommunicationPolicy::accept(*this,addr));
121 ///////////////////////////////////////////////////////////////////////////
123 template <class SPolicy>
124 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle(FileHandle other,
126 : SocketHandle<SPolicy>(other, isChecked)
129 template <class SPolicy>
130 prefix_ senf::ServerSocketHandle<SPolicy>
131 senf::ServerSocketHandle<SPolicy>::cast_static(FileHandle handle)
133 return ServerSocketHandle(handle,true);
136 template <class SPolicy>
137 prefix_ senf::ServerSocketHandle<SPolicy>
138 senf::ServerSocketHandle<SPolicy>::cast_dynamic(FileHandle handle)
140 SocketHandle<SPolicy> h (SocketHandle<SPolicy>::cast_dynamic(handle));
141 if (! static_cast<SocketBody&>(FileHandle::body(handle)).isServer())
142 throw std::bad_cast();
143 return cast_static(handle);
146 template <class SPolicy>
147 prefix_ void senf::ServerSocketHandle<SPolicy>::state(SocketStateMap & map, unsigned lod)
149 map["handle"] = prettyName(typeid(*this));
150 this->body().state(map,lod);
153 template <class SPolicy>
154 prefix_ std::string senf::ServerSocketHandle<SPolicy>::dumpState(unsigned lod)
158 return detail::dumpState(map);
161 ///////////////////////////////cti.e///////////////////////////////////////
168 // c-file-style: "senf"
169 // indent-tabs-mode: nil
170 // ispell-local-dictionary: "american"
171 // compile-command: "scons -u test"
172 // comment-column: 40