4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.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 SocketPolicy>
38 template <class OtherPolicy>
39 prefix_ senf::ServerSocketHandle<SocketPolicy>::
40 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
41 typename SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type *)
42 : SocketHandle<SocketPolicy>(other,true)
45 template <class SocketPolicy>
46 prefix_ senf::ServerSocketHandle<SocketPolicy>::
47 ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol)
48 : SocketHandle<SocketPolicy>(protocol,true)
51 template <class SocketPolicy>
52 template <class OtherPolicy>
53 prefix_ typename senf::SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type const &
54 senf::ServerSocketHandle<SocketPolicy>::operator=(ServerSocketHandle<OtherPolicy> other)
60 ///////////////////////////////////////////////////////////////////////////
61 // Server socket interface
63 template <class Policy>
64 prefix_ void senf::ServerSocketHandle<Policy>::bind(AddressParam addr)
66 Policy::AddressingPolicy::bind(*this,addr);
69 template <class Policy>
70 prefix_ void senf::ServerSocketHandle<Policy>::listen(unsigned backlog)
72 Policy::CommunicationPolicy::listen(*this,backlog);
75 template <class Policy>
76 prefix_ typename senf::ServerSocketHandle<Policy>::Address
77 senf::ServerSocketHandle<Policy>::local()
79 typename Policy::AddressingPolicy::Address addr;
84 template <class Policy>
85 prefix_ void senf::ServerSocketHandle<Policy>::local(Address & addr)
87 Policy::AddressingPolicy::local(*this,addr);
90 template <class Policy>
91 prefix_ typename senf::ServerSocketHandle<Policy>::ClientSocketHandle
92 senf::ServerSocketHandle<Policy>::accept()
95 return acceptfrom(address);
98 template <class Policy>
99 prefix_ std::pair<typename senf::ServerSocketHandle<Policy>::ClientSocketHandle,
100 typename senf::ServerSocketHandle<Policy>::Address>
101 senf::ServerSocketHandle<Policy>::acceptfrom()
105 ClientSocketHandle handle = accept(address);
106 return std::make_pair(handle,address);
109 template <class Policy>
110 prefix_ typename senf::ServerSocketHandle<Policy>::ClientSocketHandle
111 senf::ServerSocketHandle<Policy>::acceptfrom(Address & addr)
113 return ClientSocketHandle(this->protocol().clone(),
114 Policy::CommunicationPolicy::accept(*this,addr));
117 ///////////////////////////////////////////////////////////////////////////
119 template <class Policy>
120 prefix_ senf::ServerSocketHandle<Policy>::ServerSocketHandle(FileHandle other,
122 : SocketHandle<Policy>(other, isChecked)
125 template <class Policy>
126 prefix_ senf::ServerSocketHandle<Policy>
127 senf::ServerSocketHandle<Policy>::cast_static(FileHandle handle)
129 return ServerSocketHandle(handle,true);
132 template <class Policy>
133 prefix_ senf::ServerSocketHandle<Policy>
134 senf::ServerSocketHandle<Policy>::cast_dynamic(FileHandle handle)
136 SocketHandle<Policy> h (SocketHandle<Policy>::cast_dynamic(handle));
137 if (! static_cast<SocketBody&>(FileHandle::body(handle)).isServer())
138 throw std::bad_cast();
139 return cast_static(handle);
142 template <class Policy>
143 prefix_ void senf::ServerSocketHandle<Policy>::state(SocketStateMap & map, unsigned lod)
145 map["handle"] = prettyName(typeid(*this));
146 this->body().state(map,lod);
149 template <class Policy>
150 prefix_ std::string senf::ServerSocketHandle<Policy>::dumpState(unsigned lod)
154 return detail::dumpState(map);
157 ///////////////////////////////cti.e///////////////////////////////////////
163 // c-file-style: "senf"