00001 // $Id:ServerSocketHandle.hh 218 2007-03-20 14:39:32Z tho $ 00002 // 00003 // Copyright (C) 2006 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00027 #ifndef HH_SENF_Socket_ServerSocketHandle_ 00028 #define HH_SENF_Socket_ServerSocketHandle_ 1 00029 00030 // Custom includes 00031 #include <boost/call_traits.hpp> 00032 #include "SocketHandle.hh" 00033 00034 //#include "ServerSocketHandle.mpp" 00035 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00036 00037 namespace senf { 00038 00040 //\{ 00041 00042 template <class SPolicy> class ClientSocketHandle; 00043 00072 template <class SPolicy> 00073 class ServerSocketHandle 00074 : public SocketHandle<SPolicy> 00075 { 00076 public: 00077 //-//////////////////////////////////////////////////////////////////////// 00078 // Types 00079 00081 typedef typename SPolicy::AddressingPolicy::Address Address; 00083 00088 typedef typename boost::call_traits<Address>::param_type AddressParam; 00090 typedef ClientSocketHandle<SPolicy> ClientHandle; 00091 00092 //-//////////////////////////////////////////////////////////////////////// 00094 //\{ 00095 00096 // default default constructor 00097 // default copy constructor 00098 // default copy assignment 00099 // default destructor 00100 00101 // here to implement 00102 ServerSocketHandle(); 00103 00104 // conversion constructors 00105 template <class OtherPolicy> 00106 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other, 00107 typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type * = 0); 00108 00109 template <class OtherPolicy> 00110 typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const & 00111 operator=(ServerSocketHandle<OtherPolicy> other); 00112 00113 //\} 00114 //-//////////////////////////////////////////////////////////////////////// 00115 00116 //-//////////////////////////////////////////////////////////////////////// 00118 //\{ 00119 00129 void bind (AddressParam addr); 00130 00140 // Possible solution: Make listen() an abstract method of the protocol interface, make the 00141 // backlog parameter into a member living in the body or protocol class and set it using 00142 // some accessor. Hmm ... this all seems somehow futile ... 00143 void listen (unsigned backlog=0); 00144 00155 Address local (); 00156 void local (Address & addr); 00158 00171 ClientHandle accept (); 00172 std::pair<ClientHandle, Address> 00173 acceptfrom (); 00174 00179 ClientHandle acceptfrom (Address & addr); 00181 00187 //\} 00188 00189 static ServerSocketHandle cast_static(FileHandle handle); 00190 static ServerSocketHandle cast_dynamic(FileHandle handle); 00191 00192 // we need to override both since SocketHandle is *not* polymorphic 00193 void state(SocketStateMap & map, unsigned lod=0); 00194 std::string dumpState(unsigned lod=0); 00195 00196 protected: 00197 ServerSocketHandle(FileHandle other, bool isChecked); 00198 explicit ServerSocketHandle(std::auto_ptr<SocketBody> body); 00199 00200 private: 00201 00202 }; 00203 00204 //\} 00205 } 00206 00207 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00208 //#include "ServerSocketHandle.cci" 00209 //#include "ServerSocketHandle.ct" 00210 #include "ServerSocketHandle.cti" 00211 #endif 00212 00213 00214 // Local Variables: 00215 // mode: c++ 00216 // fill-column: 100 00217 // c-file-style: "senf" 00218 // indent-tabs-mode: nil 00219 // ispell-local-dictionary: "american" 00220 // compile-command: "scons -u test" 00221 // comment-column: 40 00222 // End: