switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / CommunicationPolicy.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief CommunicationPolicy public header
30  */
31
32 #ifndef HH_SENF_Socket_CommunicationPolicy_
33 #define HH_SENF_Socket_CommunicationPolicy_ 1
34
35 // Custom includes
36 #include "SocketPolicy.hh"
37 #include "AddressingPolicy.hh"
38 #include "FileHandle.hh"
39
40 //#include "CommunicationPolicy.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 struct sockaddr;
44
45 namespace senf {
46
47     /// \addtogroup policy_impl_group
48     //\{
49
50     template <class SPolicy> class ServerSocketHandle;
51
52     /** \brief CommunicationPolicy for connected sockets
53
54         The ConnectedCommunicationPolicy provides support for standard BSD socket API based
55         connected communication. It provides the server side listen() and accept() members.
56      */
57     struct ConnectedCommunicationPolicy : public CommunicationPolicyBase
58     {
59 #       ifndef DOXYGEN
60         template <class SPolicy>
61         static void listen(ServerSocketHandle<SPolicy> const & handle, unsigned backlog,
62                            typename IfAddressingPolicyIsNot<SPolicy,NoAddressingPolicy>::type * = 0);
63 #       else
64         template <class SPolicy>
65         static void listen(ServerSocketHandle<SPolicy> const & handle, unsigned backlog);
66                                         ///< Enable establishing new connections on the socket
67                                         /**< \param[in] handle socket handle to enable reception on
68                                              \param[in] backlog size of backlog queue */
69 #       endif
70
71 #       ifndef DOXYGEN
72         template <class SPolicy>
73         static int accept(ServerSocketHandle<SPolicy> const & handle,
74                           typename ServerSocketHandle<SPolicy>::Address & address,
75                           typename IfAddressingPolicyIsNot<SPolicy,NoAddressingPolicy>::type * = 0);
76 #       else
77         template <class SPolicy>
78         static int accept(ServerSocketHandle<SPolicy> const & handle,
79                           typename ServerSocketHandle<SPolicy>::Address & address);
80                                         ///< accept a new connection on the socket.
81                                         /**< The accept() member will return a new client file
82                                              descriptor. This file descriptor will be used by the
83                                              ServerSocketHandle implementation to build a new
84                                              ClientSocketHandle for the new connection.
85
86                                              \param[in] handle socket handle to accept connection on
87                                              \param[out] address address of newly connected remote
88                                                  peer
89                                              \returns file descriptor of new client socket */
90 #       endif
91
92         static int accept(FileHandle const & handle);
93                                         ///< accept a new connection on the socket.
94                                         /**< The accept() member will return a new client file
95                                              descriptor. This file descriptor will be used by the
96                                              ServerSocketHandle implementation to build a new
97                                              ClientSocketHandle for the new connection.
98
99                                              \param[in] handle socket handle to accept connection on
100                                              \returns file descriptor of new client socket */
101
102     private:
103         static void do_listen(FileHandle const & handle, unsigned backlog);
104         static int do_accept(FileHandle const & handle, struct sockaddr * addr, unsigned len);
105     };
106
107     /** \brief CommunicationPolicy for unconnected sockets
108
109         This is different from UndefinedCommunicationPolicy (which is the same as
110         CommunicationPolicyBase). This policy class defines the communication policy -- it
111         explicitly states, that the socket does not support connected communication. This
112         effectively disables the ServerSocketHandle.
113      */
114     struct UnconnectedCommunicationPolicy : public CommunicationPolicyBase
115     {};
116
117     //\}
118
119 }
120
121
122 //-/////////////////////////////////////////////////////////////////////////////////////////////////
123 #include "CommunicationPolicy.cci"
124 //#include "CommunicationPolicy.ct"
125 #include "CommunicationPolicy.cti"
126 #endif
127
128 \f
129 // Local Variables:
130 // mode: c++
131 // fill-column: 100
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // comment-column: 40
137 // End: