Fixed whitespace in all files (no tabs)
[senf.git] / Socket / ReadWritePolicy.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 /** \file
24     \brief ReadPolicy and WritePolicy public header
25
26     \todo ReadWritePolicy.test.cc
27  */
28
29 #ifndef HH_ReadWritePolicy_
30 #define HH_ReadWritePolicy_ 1
31
32 // Custom includes
33 #include "SocketPolicy.hh"
34 #include "ClientSocketHandle.hh"
35 #include "CommunicationPolicy.hh"
36
37 //#include "ReadWritePolicy.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40
41 struct sockaddr;
42
43 namespace senf {
44
45     /// \addtogroup policy_impl_group
46     /// @{
47
48     /** \brief ReadPolicy for readable sockets
49
50         This policy provides support for readable sockets via the standard UNIX read/recvfrom system
51         cals. The concreate semantics of the read calls depend on the framing policy of the socket.
52      */
53     struct ReadablePolicy : public ReadPolicyBase
54     {
55         static unsigned read(FileHandle handle, char * buffer, unsigned size);
56                                         ///< read data from socket
57                                         /**< \param[in] handle socket handle to read from
58                                              \param[in] buffer address of buffer to write data to
59                                              \param[in] size size of buffer
60                                              \returns number of bytes read */
61         template <class Policy>
62         static unsigned readfrom(ClientSocketHandle<Policy> handle, char * buffer, unsigned size,
63                                  typename Policy::AddressingPolicy::Address & address,
64                                  typename IfCommunicationPolicyIs<Policy,UnconnectedCommunicationPolicy>::type * = 0);
65                                         ///< read data from socket returning peer address
66                                         /**< \param[in] handle socket handle to read from
67                                              \param[in] buffer address of buffer to write data to
68                                              \param[in] size size of buffer
69                                              \param[out] address peer address
70                                              \returns number of bytes read */
71
72     private:
73         static unsigned do_readfrom(FileHandle handle, char * buffer, unsigned size,
74                                     struct ::sockaddr * addr, socklen_t len);
75     };
76
77     /** \brief ReadPolicy for unreadable sockets
78
79         This is different from UndefinedReadPolicy (which is the same as ReadPolicyBase). This
80         policy class defines the socket readability -- it explicitly states, that the socket does
81         not support reading.
82      */
83     struct NotReadablePolicy : public ReadPolicyBase
84     {};
85
86     /** \brief WritePolicy for writeable sockets
87
88         This policy provides support for writable sockets via the standard UNIX write/sendto system
89         cals. The concreate semantics of the write calls depend on the framing policy of the socket.
90      */
91     struct WriteablePolicy : public WritePolicyBase
92     {
93         template <class Policy>
94         static unsigned write(ClientSocketHandle<Policy> handle, char const * buffer, unsigned size,
95                               typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
96                                         ///< write data to socket
97                                         /**< This member is only enabled if the socket uses
98                                              connected communication. Otherwise the communication
99                                              partner must be specified explicitly using the sendto
100                                              call
101
102                                              \param[in] handle socket handle to write data to
103                                              \param[in] buffer address of buffer to send
104                                              \param[in] size number of bytes to write
105                                              \returns number of bytes written */
106         template <class Policy>
107         static unsigned writeto(ClientSocketHandle<Policy> handle,
108                                 typename boost::call_traits<typename Policy::AddressingPolicy::Address>::param_type addr,
109                                 char const * buffer, unsigned size,
110                                 typename IfCommunicationPolicyIs<Policy,UnconnectedCommunicationPolicy>::type * = 0);
111                                         ///< write data to socket sending to given peer
112                                         /**< This member is only enabled if the socket uses
113                                              unconnected communication. Otherwise no target may be
114                                              specified since it is implied in the connection.
115
116                                              \param[in] handle socket handle to write data to
117                                              \param[in] buffer address of buffer to send
118                                              \param[in] size number of bytes to write
119                                              \param[in] address peer to send data to
120                                              \returns number of bytes written
121                                           */
122
123     private:
124         static unsigned do_write(FileHandle handle, char const * buffer, unsigned size);
125         static unsigned do_writeto(FileHandle handle, char const * buffer, unsigned size,
126                                    struct sockaddr * addr, socklen_t len);
127     };
128
129     /** \brief WritePolicy for unwriteable sockets
130
131         This is different from UndefinedWritePolicy (which is the same as WritePolicyBase). This
132         policy class defines the socket writeability -- it explicitly states, that the socket does
133         not support writing.
134      */
135     struct NotWriteablePolicy : public WritePolicyBase
136     {};
137
138     /// @}
139
140 }
141
142
143 ///////////////////////////////hh.e////////////////////////////////////////
144 //#include "ReadWritePolicy.cci"
145 //#include "ReadWritePolicy.ct"
146 #include "ReadWritePolicy.cti"
147 #endif
148
149 \f
150 // Local Variables:
151 // mode: c++
152 // fill-column: 100
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // End: