ClientSocketHandle.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 
18 #ifndef HH_SENF_Socket_ClientSocketHandle_
19 #define HH_SENF_Socket_ClientSocketHandle_ 1
20 
21 // Custom includes
22 #include <boost/call_traits.hpp>
23 #include <boost/range/iterator.hpp>
24 #include <boost/type_traits/is_convertible.hpp>
25 #include <boost/optional.hpp>
26 #include "SocketHandle.hh"
27 
28 //#include "ClientSocketHandle.mpp"
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 
34  //\{
35 
36  template <class SPolicy> class ServerSocketHandle;
37 
87  template <class SPolicy>
89  : public SocketHandle<SPolicy>
90  {
91  public:
92  //-////////////////////////////////////////////////////////////////////////
93  // Types
94 
96  typedef typename SPolicy::AddressingPolicy::Address Address;
98 
103  typedef typename boost::call_traits<Address>::param_type AddressParam;
105 
109 
110  //-////////////////////////////////////////////////////////////////////////
112  //\{
113 
114  // default default constructor
115  // default copy constructor
116  // default copy assignment
117  // default destructor
118 
119  // here to implement
121 
122  // conversion constructors
123 # ifndef DOXYGEN
124  template <class OtherPolicy>
127 # else
129 # endif
130 
131 # ifndef DOXYGEN
132  template <class OtherPolicy>
135 # else
136  template <class OtherPolicy>
138 # endif
139 
140  //\}
141  //-////////////////////////////////////////////////////////////////////////
142 
143  //-////////////////////////////////////////////////////////////////////////
145  //\{
146 
177  std::string read (unsigned limit=0);
178 
179 # ifndef DOXYGEN
180  template <class ForwardWritableRange>
181  typename boost::disable_if< boost::is_convertible<ForwardWritableRange,unsigned>,
182  typename boost::range_iterator<ForwardWritableRange>::type>::type
183  read(ForwardWritableRange const & range);
184 # else
185  template <class ForwardWritableRange>
186  typename boost::range_iterator<ForwardWritableRange>::type
187  read (ForwardWritableRange const & range);
189 
200 # endif
201 # ifndef DOXYGEN
202  template <class ForwardWritableRange>
203  typename boost::disable_if< boost::is_convertible<ForwardWritableRange,unsigned>,
204  typename boost::range_iterator<ForwardWritableRange>::type>::type
205  read(ForwardWritableRange & range);
206 # else
207  template <class ForwardWritableRange>
208  typename boost::range_iterator<ForwardWritableRange>::type
209  read (ForwardWritableRange & range);
211 
214 # endif
215  template <class Sequence>
216  void read (Sequence & container, unsigned limit);
218 
225  char * read (char * start, char * end);
227 
252  std::pair<std::string, Address>
253  readfrom (unsigned limit=0);
254  template <class ForwardWritableRange>
255  typename boost::range_iterator<ForwardWritableRange const>::type
256  readfrom (ForwardWritableRange const & range, Address & from);
258 
271  template <class ForwardWritableRange>
272  typename boost::range_iterator<ForwardWritableRange>::type
273  readfrom (ForwardWritableRange & range, Address & from);
275 
278  template <class Sequence>
279  void readfrom (Sequence & container, Address & from, unsigned limit);
281 
290  char * readfrom (char * start, char * end, Address & from);
292 
323  template <class ForwardReadableRange>
324  typename boost::range_const_iterator<ForwardReadableRange const>::type
325  write (ForwardReadableRange const & range);
326  char const * write (char const * start, char const * end);
328 
352  template <class ForwardReadableRange>
353  typename boost::range_const_iterator<ForwardReadableRange const>::type
354  writeto (AddressParam addr, ForwardReadableRange const & range);
355  char const * writeto (AddressParam addr, char const * start, char const * end);
357 
364  //\}
365 
366  //-////////////////////////////////////////////////////////////////////////
368 
395  boost::optional<typename SPolicy::ReadPolicy::Buffer> dequeue();
396 
397  void release();
398 
432  boost::optional<typename SPolicy::WritePolicy::Buffer> enqueue();
433 
434  bool send();
435 
438  //\}
439  //-////////////////////////////////////////////////////////////////////////
441  //\{
442 
453  void connect (AddressParam addr) const;
454 
464  void bind (AddressParam addr) const;
465 
477  Address peer () const;
478  void peer (Address & addr) const;
480 
492  Address local () const;
493  void local (Address & addr) const;
495 
497  //\}
498 
501 
502  // we need to override both since SocketHandle is *not* polymorphic
503  void state(SocketStateMap & map, unsigned lod=0);
504  std::string dumpState(unsigned lod=0);
505 
506  unsigned available();
507 
508  protected:
509  ClientSocketHandle(FileHandle other, bool isChecked);
510  explicit ClientSocketHandle(std::unique_ptr<SocketBody> body);
511 
512  private:
513  friend class senf::ServerSocketHandle<SPolicy>;
514  };
515 
516  //\}
517 }
518 
519 //-/////////////////////////////////////////////////////////////////////////////////////////////////
520 //#include "ClientSocketHandle.cci"
521 #include "ClientSocketHandle.ct"
522 #include "ClientSocketHandle.cti"
523 #endif
524 
525 
526 // Local Variables:
527 // mode: c++
528 // fill-column: 100
529 // c-file-style: "senf"
530 // indent-tabs-mode: nil
531 // ispell-local-dictionary: "american"
532 // compile-command: "scons -u test"
533 // comment-column: 40
534 // End:
bool send()
Send all data in the write queue.
ClientSocketHandle< OtherPolicy > const & operator=(ClientSocketHandle< OtherPolicy > other)
std::string dumpState(unsigned lod=0)
boost::call_traits< Address >::param_type AddressParam
&#39;Best&#39; type for passing address as parameter
boost::optional< typename SPolicy::ReadPolicy::Buffer > dequeue()
Read data from packet queue.
Generic SocketHandle with client interface.
Generic SocketHandle with server interface.
void state(SocketStateMap &map, unsigned lod=0)
static ClientSocketHandle cast_dynamic(FileHandle handle)
boost::optional< typename SPolicy::WritePolicy::Buffer > enqueue()
Write data to packet queue.
Basic file handle wrapper.
Definition: FileHandle.hh:102
void bind(AddressParam addr) const
Set local address.
void connect(AddressParam addr) const
Connect to remote peer.
std::string read(unsigned limit=0)
Read data from socket.
boost::range_const_iterator< ForwardReadableRange const >::type writeto(AddressParam addr, ForwardReadableRange const &range)
Write data to unconnected socket.
void release()
Release all queue frames to the kernel.
basic SocketHandle supporting protocol and policy abstraction
Definition: SocketHandle.hh:60
Address local() const
Query local address.
static ClientSocketHandle cast_static(FileHandle handle)
SocketBody & body()
Access socket body.
Address peer() const
Query remote address.
SocketHandle public header.
Check policy compatibility.
Definition: SocketHandle.hh:76
SPolicy::AddressingPolicy::Address Address
Address type from the addressing policy.
boost::range_const_iterator< ForwardReadableRange const >::type write(ForwardReadableRange const &range)
Write data to socket.
std::pair< std::string, Address > readfrom(unsigned limit=0)
Read data from unconnected socket returning address.
ServerSocketHandle< SPolicy > ServerHandle
Corresponding server socket handle with the same policy.