Further documentation (mainly SocketPolicy)
[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     template <class Policy>
46     class ServerSocketHandle
47         : public SocketHandle<Policy>
48     {
49     public:
50         ///////////////////////////////////////////////////////////////////////////
51         // Types
52
53         typedef typename Policy::AddressingPolicy::Address Address;
54         typedef typename boost::call_traits<Address>::param_type AddressParam;
55         typedef ClientSocketHandle<Policy> ClientSocketHandle;
56
57         ///////////////////////////////////////////////////////////////////////////
58         ///\name Structors and default members
59         ///@{
60
61         // no default constructor
62         // default copy constructor
63         // default copy assignment
64         // default destructor
65
66         // conversion constructors
67         template <class OtherPolicy>
68         ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
69                            typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
70
71         template <class OtherPolicy>
72         typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const & 
73         operator=(ServerSocketHandle<OtherPolicy> other);
74
75         ///@}
76         ///////////////////////////////////////////////////////////////////////////
77
78         ///////////////////////////////////////////////////////////////////////////
79         ///\name Server socket interface
80         ///@{
81
82         void         bind         (AddressParam addr);
83         void         listen       (unsigned backlog=0);
84
85         Address      local        ();
86         void         local        (Address & addr);
87
88         // If the handle is non-blocking, accept will NOT block. If no connection
89         // is available to be returned, accept will return a ClientSocketHandle
90         // which is not valid()
91         ClientSocketHandle 
92                      accept       ();
93         std::pair<ClientSocketHandle, Address>
94                      acceptfrom   ();
95         ClientSocketHandle
96                      acceptfrom   (Address & addr);
97         
98         ///@}
99
100         static ServerSocketHandle cast_static(FileHandle handle);
101         static ServerSocketHandle cast_dynamic(FileHandle handle);
102
103         // we need to override both since SocketHandle is *not* polymorphic
104         void state(SocketStateMap & map, unsigned lod=0);
105         std::string dumpState(unsigned lod=0);
106
107     protected:
108         ServerSocketHandle(FileHandle other, bool isChecked);
109         explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol);
110
111     private:
112         
113     };
114
115     /// @}
116 }
117
118 ///////////////////////////////hh.e////////////////////////////////////////
119 //#include "ServerSocketHandle.cci"
120 //#include "ServerSocketHandle.ct"
121 #include "ServerSocketHandle.cti"
122 #endif
123
124 \f
125 // Local Variables:
126 // mode: c++
127 // c-file-style: "senf"
128 // End: