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