4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
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.
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.
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.
24 \brief ReadPolicy and WritePolicy public header
26 \todo ReadWritePolicy.test.cc
29 #ifndef HH_ReadWritePolicy_
30 #define HH_ReadWritePolicy_ 1
33 #include "SocketPolicy.hh"
34 #include "ClientSocketHandle.hh"
35 #include "CommunicationPolicy.hh"
37 //#include "ReadWritePolicy.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
45 /// \addtogroup policy_impl_group
48 /** \brief ReadPolicy for readable sockets
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.
53 struct ReadablePolicy : public ReadPolicyBase
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 */
73 static unsigned do_readfrom(FileHandle handle, char * buffer, unsigned size,
74 struct ::sockaddr * addr, socklen_t len);
77 /** \brief ReadPolicy for unreadable sockets
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
83 struct NotReadablePolicy : public ReadPolicyBase
86 /** \brief WritePolicy for writeable sockets
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.
91 struct WriteablePolicy : public WritePolicyBase
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
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.
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
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);
129 /** \brief WritePolicy for unwriteable sockets
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
135 struct NotWriteablePolicy : public WritePolicyBase
143 ///////////////////////////////hh.e////////////////////////////////////////
144 //#include "ReadWritePolicy.cci"
145 //#include "ReadWritePolicy.ct"
146 #include "ReadWritePolicy.cti"
152 // c-file-style: "senf"