4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ReadPolicy and WritePolicy public header
31 \todo ReadWritePolicy.test.cc
34 #ifndef HH_SENF_Socket_ReadWritePolicy_
35 #define HH_SENF_Socket_ReadWritePolicy_ 1
38 #include "SocketPolicy.hh"
39 #include "ClientSocketHandle.hh"
40 #include "CommunicationPolicy.hh"
42 //#include "ReadWritePolicy.mpp"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 /// \addtogroup policy_impl_group
53 /** \brief ReadPolicy for readable sockets
55 This policy provides support for readable sockets via the standard UNIX read/recvfrom system
56 calls. The concrete semantics of the read calls depend on the framing policy of the socket.
58 struct ReadablePolicy : public ReadPolicyBase
60 static unsigned read(FileHandle & handle, char * buffer, unsigned size);
61 ///< read data from socket
62 /**< \param[in] handle socket handle to read from
63 \param[in] buffer address of buffer to write data to
64 \param[in] size size of buffer
65 \returns number of bytes read */
67 template <class SPolicy>
68 static unsigned readfrom(ClientSocketHandle<SPolicy> & handle, char * buffer, unsigned size,
69 typename SPolicy::AddressingPolicy::Address & address,
70 typename IfCommunicationPolicyIs<
71 SPolicy,UnconnectedCommunicationPolicy>::type * = 0);
73 template <class SPolicy>
74 static unsigned readfrom(ClientSocketHandle<SPolicy> & handle, char * buffer, unsigned size,
75 typename Policy::AddressingPolicy::Address & address);
76 ///< read data from socket returning peer address
77 /**< \param[in] handle socket handle to read from
78 \param[in] buffer address of buffer to write data to
79 \param[in] size size of buffer
80 \param[out] address peer address
81 \returns number of bytes read */
85 static unsigned do_readfrom(FileHandle & handle, char * buffer, unsigned size,
86 struct ::sockaddr * addr, socklen_t * len);
89 /** \brief ReadPolicy for unreadable sockets
91 This is different from UndefinedReadPolicy (which is the same as ReadPolicyBase). This
92 policy class defines the socket readability -- it explicitly states, that the socket does
95 struct NotReadablePolicy : public ReadPolicyBase
98 /** \brief WritePolicy for writeable sockets
100 This policy provides support for writable sockets via the standard UNIX write/sendto system
101 calls. The concrete semantics of the write calls depend on the framing policy of the socket.
103 struct WriteablePolicy : public WritePolicyBase
106 template <class SPolicy>
107 static unsigned write(ClientSocketHandle<SPolicy> & handle, char const * buffer, unsigned size,
108 typename IfCommunicationPolicyIs<
109 SPolicy,ConnectedCommunicationPolicy>::type * = 0);
111 template <class SPolicy>
112 static unsigned write(ClientSocketHandle<SPolicy> & handle, char const * buffer,
114 ///< write data to socket
115 /**< This member is only enabled if the socket uses
116 connected communication. Otherwise the communication
117 partner must be specified explicitly using the sendto
120 \param[in] handle socket handle to write data to
121 \param[in] buffer address of buffer to send
122 \param[in] size number of bytes to write
123 \returns number of bytes written */
126 template <class SPolicy>
127 static unsigned writeto(ClientSocketHandle<SPolicy> & handle,
128 typename boost::call_traits<
129 typename SPolicy::AddressingPolicy::Address>::param_type addr,
130 char const * buffer, unsigned size,
131 typename IfCommunicationPolicyIs<
132 SPolicy,UnconnectedCommunicationPolicy>::type * = 0);
134 template <class SPolicy>
135 static unsigned writeto(ClientSocketHandle<SPolicy> & handle,
136 typename Policy::AddressingPolicy::Address const & addr,
137 char const * buffer, unsigned size);
138 ///< write data to socket sending to given peer
139 /**< This member is only enabled if the socket uses
140 unconnected communication. Otherwise no target may be
141 specified since it is implied in the connection.
143 \param[in] handle socket handle to write data to
144 \param[in] buffer address of buffer to send
145 \param[in] size number of bytes to write
146 \param[in] addr peer to send data to
147 \returns number of bytes written
152 static unsigned do_write(FileHandle & handle, char const * buffer, unsigned size);
153 static unsigned do_writeto(FileHandle & handle, char const * buffer, unsigned size,
154 struct sockaddr const * addr, socklen_t len);
157 /** \brief WritePolicy for unwriteable sockets
159 This is different from UndefinedWritePolicy (which is the same as WritePolicyBase). This
160 policy class defines the socket writeability -- it explicitly states, that the socket does
163 struct NotWriteablePolicy : public WritePolicyBase
171 //-/////////////////////////////////////////////////////////////////////////////////////////////////
172 //#include "ReadWritePolicy.cci"
173 //#include "ReadWritePolicy.ct"
174 #include "ReadWritePolicy.cti"
181 // c-file-style: "senf"
182 // indent-tabs-mode: nil
183 // ispell-local-dictionary: "american"
184 // compile-command: "scons -u test"
185 // comment-column: 40