BSDAddressingPolicy.cti
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 
14 /** \file
15  \brief BSDAddressingPolicyMixin inline template implementation
16  */
17 
18 //#include "BSDAddressingPolicy.ih"
19 
20 // Custom includes
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::BSDAddressingPolicyMixin<Address>
27 
28 #ifndef DOXYGEN
29 template <class Address>
30 template <class SPolicy>
31 prefix_ void senf::BSDAddressingPolicyMixin<Address>::
32 peer(SocketHandle<SPolicy> const & handle, Address & addr,
33  typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type *)
34 {
35  try {
36  do_peer(handle,addr.sockaddr_p(),addr.socklen_p());
37  } catch (Exception & e) {
38  e << "; could not get peer for address \"" << addr << "\"";
39  throw;
40  }
41 }
42 #else
43 template <class Address>
44 template <class SPolicy>
45 prefix_ void senf::BSDAddressingPolicyMixin<Address>::
46 peer(SocketHandle<SPolicy> const & handle, Address & addr)
47 {}
48 #endif
49 
50 #ifndef DOXYGEN
51 template <class Address>
52 template <class SPolicy>
53 prefix_ void senf::BSDAddressingPolicyMixin<Address>::
54 connect(SocketHandle<SPolicy> const & handle, Address const & addr,
55  typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type *)
56 {
57  try {
58  do_connect(handle,addr.sockaddr_p(),addr.socklen());
59  } catch (Exception & e) {
60  e << "; could not connect to address \"" << addr << "\"";
61  throw;
62  }
63 }
64 #else
65 template <class Address>
66 template <class SPolicy>
67 prefix_ void senf::BSDAddressingPolicyMixin<Address>::
68 connect(SocketHandle<SPolicy> const & handle, Address const & addr)
69 {}
70 #endif
71 
72 template <class Address>
73 prefix_ void senf::BSDAddressingPolicyMixin<Address>::local(FileHandle const & handle,
74  Address & addr)
75 {
76  try {
77  do_local(handle,addr.sockaddr_p(),addr.socklen_p());
78  } catch (Exception & e) {
79  // TODO: identify socket by some meaningful attribute
80  e << "; could not get name for address \"" << addr << "\"";
81  throw;
82  }
83 }
84 
85 template <class Address>
86 prefix_ void senf::BSDAddressingPolicyMixin<Address>::bind(FileHandle const & handle,
87  Address const & addr)
88 {
89  try {
90  do_bind(handle,addr.sockaddr_p(),addr.socklen());
91  } catch (Exception & e) {
92  e << "; could not bind to address \"" << addr << "\"";
93  throw;
94  }
95 }
96 
97 //-/////////////////////////////////////////////////////////////////////////////////////////////////
98 #undef prefix_
99 
100 
101 // Local Variables:
102 // mode: c++
103 // fill-column: 100
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u ../test"
108 // comment-column: 40
109 // End: