40ce4bb85d5868ec28983c210ad1b1443733a6fb
[senf.git] / Socket / ServerSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 #ifndef HH_ServerSocketHandle_
24 #define HH_ServerSocketHandle_ 1
25
26 // Custom includes
27 #include <boost/static_assert.hpp>
28 #include <boost/call_traits.hpp>
29 #include "SocketHandle.hh"
30 #include "CommunicationPolicy.hh"
31 #include "AddressingPolicy.hh"
32
33 //#include "ServerSocketHandle.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37
38     /// \addtogroup handle_group
39     /// @{
40
41     template <class Policy> class ClientSocketHandle;
42
43     /** \brief
44
45         <table>
46         <tr><td>senf::ServerSocketHandle::bind</td>       <td>AddressingPolicy::bind (\ref senf::AddressingPolicyBase)</td></tr>
47         <tr><td>senf::ServerSocketHandle::listen</td>     <td>CommunicationPolicy::listen (\ref senf::CommunicationPolicyBase)</td></tr>
48         <tr><td>senf::ServerSocketHandle::local</td>      <td>AddressingPolicy::local (\ref senf::AddressingPolicyBase)</td></tr>
49         <tr><td>senf::ServerSocketHandle::accept</td>     <td>CommunicationPolicy::accept (\ref senf::CommunicationPolicyBase)</td></tr>
50         <tr><td>senf::ServerSocketHandle::acceptfrom</td> <td>CommunicationPolicy::accept (\ref senf::CommunicationPolicyBase)</td></tr>
51         </table>
52         
53       */
54     template <class Policy>
55     class ServerSocketHandle
56         : public SocketHandle<Policy>
57     {
58     public:
59         ///////////////////////////////////////////////////////////////////////////
60         // Types
61
62         typedef typename Policy::AddressingPolicy::Address Address;
63         typedef typename boost::call_traits<Address>::param_type AddressParam;
64         typedef ClientSocketHandle<Policy> ClientSocketHandle;
65
66         ///////////////////////////////////////////////////////////////////////////
67         ///\name Structors and default members
68         ///@{
69
70         // no default constructor
71         // default copy constructor
72         // default copy assignment
73         // default destructor
74
75         // conversion constructors
76         template <class OtherPolicy>
77         ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
78                            typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
79
80         template <class OtherPolicy>
81         typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const & 
82         operator=(ServerSocketHandle<OtherPolicy> other);
83
84         ///@}
85         ///////////////////////////////////////////////////////////////////////////
86
87         ///////////////////////////////////////////////////////////////////////////
88         ///\name Server socket interface
89         ///@{
90
91         void         bind         (AddressParam addr);
92         void         listen       (unsigned backlog=0);
93
94         Address      local        ();
95         void         local        (Address & addr);
96
97         // If the handle is non-blocking, accept will NOT block. If no connection
98         // is available to be returned, accept will return a ClientSocketHandle
99         // which is not valid()
100         ClientSocketHandle 
101                      accept       ();
102         std::pair<ClientSocketHandle, Address>
103                      acceptfrom   ();
104         ClientSocketHandle
105                      acceptfrom   (Address & addr);
106         
107         ///@}
108
109         static ServerSocketHandle cast_static(FileHandle handle);
110         static ServerSocketHandle cast_dynamic(FileHandle handle);
111
112         // we need to override both since SocketHandle is *not* polymorphic
113         void state(SocketStateMap & map, unsigned lod=0);
114         std::string dumpState(unsigned lod=0);
115
116     protected:
117         ServerSocketHandle(FileHandle other, bool isChecked);
118         explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol);
119
120     private:
121         
122     };
123
124     /// @}
125 }
126
127 ///////////////////////////////hh.e////////////////////////////////////////
128 //#include "ServerSocketHandle.cci"
129 //#include "ServerSocketHandle.ct"
130 #include "ServerSocketHandle.cti"
131 #endif
132
133 \f
134 // Local Variables:
135 // mode: c++
136 // c-file-style: "senf"
137 // End: