Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

ServerSocketHandle.cti

Go to the documentation of this file.
00001 // $Id: ServerSocketHandle.cti 1742 2010-11-04 14:51:56Z g0dil $
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 // Definition of inline template functions
00028 
00029 //#include "ServerSocketHandle.ih"
00030 
00031 // Custom includes
00032 #include <typeinfo>
00033 
00034 #define prefix_ inline
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 template <class SPolicy>
00038 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle()
00039 {}
00040 
00041 template <class SPolicy>
00042 template <class OtherPolicy>
00043 prefix_ senf::ServerSocketHandle<SPolicy>::
00044 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
00045                    typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type *)
00046     : SocketHandle<SPolicy>(other,true)
00047 {}
00048 
00049 template <class SPolicy>
00050 prefix_  senf::ServerSocketHandle<SPolicy>::
00051 ServerSocketHandle(std::auto_ptr<SocketBody> body)
00052     : SocketHandle<SPolicy>(body)
00053 {}
00054 
00055 template <class SPolicy>
00056 template <class OtherPolicy>
00057 prefix_ typename senf::SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const &
00058 senf::ServerSocketHandle<SPolicy>::operator=(ServerSocketHandle<OtherPolicy> other)
00059 {
00060     assign(other);
00061     return *this;
00062 }
00063 
00064 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00065 // Server socket interface
00066 
00067 template <class SPolicy>
00068 prefix_ void senf::ServerSocketHandle<SPolicy>::bind(AddressParam addr)
00069 {
00070     SPolicy::AddressingPolicy::bind(*this,addr);
00071 }
00072 
00073 template <class SPolicy>
00074 prefix_ void senf::ServerSocketHandle<SPolicy>::listen(unsigned backlog)
00075 {
00076     SPolicy::CommunicationPolicy::listen(*this,backlog);
00077 }
00078 
00079 template <class SPolicy>
00080 prefix_ typename senf::ServerSocketHandle<SPolicy>::Address
00081 senf::ServerSocketHandle<SPolicy>::local()
00082 {
00083     typename SPolicy::AddressingPolicy::Address addr;
00084     this->local(addr);
00085     return addr;
00086 }
00087 
00088 template <class SPolicy>
00089 prefix_ void senf::ServerSocketHandle<SPolicy>::local(Address & addr)
00090 {
00091     SPolicy::AddressingPolicy::local(*this,addr);
00092 }
00093 
00094 template <class SPolicy>
00095 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientHandle
00096 senf::ServerSocketHandle<SPolicy>::accept()
00097 {
00098     return ClientHandle(this->body().clone(
00099                             SPolicy::CommunicationPolicy::accept(*this), false));
00100 }
00101 
00102 template <class SPolicy>
00103 prefix_ std::pair<typename senf::ServerSocketHandle<SPolicy>::ClientHandle,
00104                   typename senf::ServerSocketHandle<SPolicy>::Address>
00105 senf::ServerSocketHandle<SPolicy>::acceptfrom()
00106 {
00107 
00108     Address address;
00109     ClientHandle handle = acceptfrom(address);
00110     return std::make_pair(handle,address);
00111 }
00112 
00113 template <class SPolicy>
00114 prefix_ typename senf::ServerSocketHandle<SPolicy>::ClientHandle
00115 senf::ServerSocketHandle<SPolicy>::acceptfrom(Address & addr)
00116 {
00117     return ClientHandle(this->body().clone(
00118                             SPolicy::CommunicationPolicy::accept(*this,addr), false));
00119 }
00120 
00121 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00122 
00123 template <class SPolicy>
00124 prefix_ senf::ServerSocketHandle<SPolicy>::ServerSocketHandle(FileHandle other,
00125                                                                     bool isChecked)
00126     : SocketHandle<SPolicy>(other, isChecked)
00127 {}
00128 
00129 template <class SPolicy>
00130 prefix_ senf::ServerSocketHandle<SPolicy>
00131 senf::ServerSocketHandle<SPolicy>::cast_static(FileHandle handle)
00132 {
00133     return ServerSocketHandle(handle,true);
00134 }
00135 
00136 template <class SPolicy>
00137 prefix_ senf::ServerSocketHandle<SPolicy>
00138 senf::ServerSocketHandle<SPolicy>::cast_dynamic(FileHandle handle)
00139 {
00140     SocketHandle<SPolicy> h (SocketHandle<SPolicy>::cast_dynamic(handle));
00141     if (! static_cast<SocketBody&>(FileHandle::body(handle)).isServer())
00142         throw std::bad_cast();
00143     return cast_static(handle);
00144 }
00145 
00146 template <class SPolicy>
00147 prefix_ void senf::ServerSocketHandle<SPolicy>::state(SocketStateMap & map, unsigned lod)
00148 {
00149     map["handle"] = prettyName(typeid(*this));
00150     if (this->valid()) {
00151         map["valid"] << "true";
00152         this->body().state(map,lod);
00153     } else
00154         map["valid"] << "false";
00155 }
00156 
00157 template <class SPolicy>
00158 prefix_ std::string senf::ServerSocketHandle<SPolicy>::dumpState(unsigned lod)
00159 {
00160     SocketStateMap map;
00161     state(map,lod);
00162     return detail::dumpState(map);
00163 }
00164 
00165 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00166 #undef prefix_
00167 
00168 
00169 // Local Variables:
00170 // mode: c++
00171 // fill-column: 100
00172 // c-file-style: "senf"
00173 // indent-tabs-mode: nil
00174 // ispell-local-dictionary: "american"
00175 // compile-command: "scons -u test"
00176 // comment-column: 40
00177 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research