c007d7390c09472abdea7845d3dbfc6c526562d8
[senf.git] / senf / Socket / CommunicationPolicy.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 /** \file
24     \brief CommunicationPolicy public header
25  */
26
27 #ifndef HH_SENF_Socket_CommunicationPolicy_
28 #define HH_SENF_Socket_CommunicationPolicy_ 1
29
30 // Custom includes
31 #include "SocketPolicy.hh"
32 #include "AddressingPolicy.hh"
33 #include "FileHandle.hh"
34
35 //#include "CommunicationPolicy.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 struct sockaddr;
39
40 namespace senf {
41
42     /// \addtogroup policy_impl_group
43     /// @{
44
45     template <class SPolicy> class ServerSocketHandle;
46
47     /** \brief CommunicationPolicy for connected sockets
48
49         The ConnectedCommunicationPolicy provides support for standard BSD socket API based
50         connected communication. It provides the server side listen() and accept() members.
51      */
52     struct ConnectedCommunicationPolicy : public CommunicationPolicyBase
53     {
54 #       ifndef DOXYGEN
55         template <class SPolicy>
56         static void listen(ServerSocketHandle<SPolicy> const & handle, unsigned backlog,
57                            typename IfAddressingPolicyIsNot<SPolicy,NoAddressingPolicy>::type * = 0);
58 #       else
59         template <class SPolicy>
60         static void listen(ServerSocketHandle<SPolicy> const & handle, unsigned backlog);
61                                         ///< Enable establishing new connections on the socket
62                                         /**< \param[in] handle socket handle to enable reception on
63                                              \param[in] backlog size of backlog queue */
64 #       endif
65
66 #       ifndef DOXYGEN
67         template <class SPolicy>
68         static int accept(ServerSocketHandle<SPolicy> const & handle,
69                           typename ServerSocketHandle<SPolicy>::Address & address,
70                           typename IfAddressingPolicyIsNot<SPolicy,NoAddressingPolicy>::type * = 0);
71 #       else
72         template <class SPolicy>
73         static int accept(ServerSocketHandle<SPolicy> const & handle,
74                           typename ServerSocketHandle<SPolicy>::Address & address);
75                                         ///< accept a new connection on the socket.
76                                         /**< The accept() member will return a new client file
77                                              descriptor. This file descriptor will be used by the
78                                              ServerSocketHandle implementation to build a new
79                                              ClientSocketHandle for the new connection.
80
81                                              \param[in] handle socket handle to accept connection on
82                                              \param[out] address address of newly connected remote
83                                                  peer
84                                              \returns file descriptor of new client socket */
85 #       endif
86
87         static int accept(FileHandle const & handle);
88                                         ///< accept a new connection on the socket.
89                                         /**< The accept() member will return a new client file
90                                              descriptor. This file descriptor will be used by the
91                                              ServerSocketHandle implementation to build a new
92                                              ClientSocketHandle for the new connection.
93
94                                              \param[in] handle socket handle to accept connection on
95                                              \returns file descriptor of new client socket */
96
97     private:
98         static void do_listen(FileHandle const & handle, unsigned backlog);
99         static int do_accept(FileHandle const & handle, struct sockaddr * addr, unsigned len);
100     };
101
102     /** \brief CommunicationPolicy for unconnected sockets
103
104         This is different from UndefinedCommunicationPolicy (which is the same as
105         CommunicationPolicyBase). This policy class defines the communication policy -- it
106         explicitly states, that the socket does not support connected communication. This
107         effectively disables the ServerSocketHandle.
108      */
109     struct UnconnectedCommunicationPolicy : public CommunicationPolicyBase
110     {};
111
112     /// @}
113
114 }
115
116
117 ///////////////////////////////hh.e////////////////////////////////////////
118 #include "CommunicationPolicy.cci"
119 //#include "CommunicationPolicy.ct"
120 #include "CommunicationPolicy.cti"
121 #endif
122
123 \f
124 // Local Variables:
125 // mode: c++
126 // fill-column: 100
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"
131 // comment-column: 40
132 // End: