ReadWritePolicy.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
20 #ifndef HH_SENF_Socket_ReadWritePolicy_
21 #define HH_SENF_Socket_ReadWritePolicy_ 1
22 
23 // Custom includes
24 #include <sys/socket.h>
25 #include "SocketPolicy.hh"
26 #include "ClientSocketHandle.hh"
27 #include "CommunicationPolicy.hh"
28 
29 //#include "ReadWritePolicy.mpp"
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 
33 struct sockaddr;
34 
35 namespace senf {
36 
38  //\{
39 
46  {
47  static unsigned read(FileHandle & handle, char * buffer, unsigned size);
49 
53 # ifndef DOXYGEN
54  template <class SPolicy>
55  static unsigned readfrom(ClientSocketHandle<SPolicy> & handle, char * buffer, unsigned size,
56  typename SPolicy::AddressingPolicy::Address & address,
57  typename IfCommunicationPolicyIs<
58  SPolicy,UnconnectedCommunicationPolicy>::type * = 0);
59 # else
60  template <class SPolicy>
61  static unsigned readfrom(ClientSocketHandle<SPolicy> & handle, char * buffer, unsigned size,
62  typename Policy::AddressingPolicy::Address & address);
64 
69 # endif
70 
71  private:
72  static unsigned do_readfrom(FileHandle & handle, char * buffer, unsigned size,
73  struct ::sockaddr * addr, socklen_t * len);
74  };
75 
83  {};
84 
91  {
92 # ifndef DOXYGEN
93  template <class SPolicy>
94  static unsigned write(ClientSocketHandle<SPolicy> & handle, char const * buffer, unsigned size,
95  typename IfCommunicationPolicyIs<
96  SPolicy,ConnectedCommunicationPolicy>::type * = 0);
97 # else
98  template <class SPolicy>
99  static unsigned write(ClientSocketHandle<SPolicy> & handle, char const * buffer,
100  unsigned size);
102 
111 # endif
112 # ifndef DOXYGEN
113  template <class SPolicy>
114  static unsigned writeto(ClientSocketHandle<SPolicy> & handle,
115  typename boost::call_traits<
116  typename SPolicy::AddressingPolicy::Address>::param_type addr,
117  char const * buffer, unsigned size,
118  typename IfCommunicationPolicyIs<
119  SPolicy,UnconnectedCommunicationPolicy>::type * = 0);
120 # else
121  template <class SPolicy>
122  static unsigned writeto(ClientSocketHandle<SPolicy> & handle,
123  typename Policy::AddressingPolicy::Address const & addr,
124  char const * buffer, unsigned size);
126 
136 # endif
137 
138  private:
139  static unsigned do_write(FileHandle & handle, char const * buffer, unsigned size);
140  static unsigned do_writeto(FileHandle & handle, char const * buffer, unsigned size,
141  struct sockaddr const * addr, socklen_t len);
142  };
143 
151  {};
152 
153  //\}
154 
155 }
156 
157 
158 //-/////////////////////////////////////////////////////////////////////////////////////////////////
159 //#include "ReadWritePolicy.cci"
160 //#include "ReadWritePolicy.ct"
161 #include "ReadWritePolicy.cti"
162 #endif
163 
164 
165 // Local Variables:
166 // mode: c++
167 // fill-column: 100
168 // c-file-style: "senf"
169 // indent-tabs-mode: nil
170 // ispell-local-dictionary: "american"
171 // compile-command: "scons -u test"
172 // comment-column: 40
173 // End:
ClientSocketHandle public header.
CommunicationPolicy public header.
Generic SocketHandle with client interface.
CommunicationPolicy for connected sockets.
Policy Framework public header.
u8 type
WritePolicy for unwriteable sockets.
WritePolicy for writeable sockets.
static unsigned readfrom(ClientSocketHandle< SPolicy > &handle, char *buffer, unsigned size, typename Policy::AddressingPolicy::Address &address)
read data from socket returning peer address
Basic file handle wrapper.
Definition: FileHandle.hh:102
Policy defining the readability.
ReadPolicy for readable sockets.
ReadPolicy for unreadable sockets.
CommunicationPolicy for unconnected sockets.
static unsigned read(FileHandle &handle, char *buffer, unsigned size)
read data from socket
Policy defining the writability.