Socket/Protocols/INet: Extend INet6SocketAddress syntax to support more flexible...
[senf.git] / Socket / Protocols / GenericAddressingPolicy.cti
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief GenericAddressingPolicy inline template implementation
25  */
26
27 //#include "GenericAddressingPolicy.ih"
28
29 // Custom includes
30
31 #define prefix_ inline
32 ///////////////////////////////cti.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::GenericAddressingPolicy<Address>
36
37 #ifndef DOXYGEN
38 template <class Address>
39 template <class SPolicy>
40 prefix_ void senf::GenericAddressingPolicy<Address>::
41 peer(SocketHandle<SPolicy> handle, Address & addr,
42      typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type *)
43 {
44     addr.clear();
45     try {
46         do_peer(handle,addr.sockaddr_p(),addr.sockaddr_len());
47     } catch (Exception & e) {
48         e << "; could not get peer for address \"" << addr << "\"";
49         throw;
50     }
51 }
52 #else
53 template <class Address>
54 template <class SPolicy>
55 prefix_ void senf::GenericAddressingPolicy<Address>::
56 peer(SocketHandle<SPolicy> handle, Address & addr)
57 {}
58 #endif
59
60 #ifndef DOXYGEN
61 template <class Address>
62 template <class SPolicy>
63 prefix_ void senf::GenericAddressingPolicy<Address>::
64 connect(SocketHandle<SPolicy> handle, Address const & addr,
65         typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type *)
66 {
67     try {
68         do_connect(handle,addr.sockaddr_p(),addr.sockaddr_len());
69     } catch (Exception & e) {
70         e << "; could not connect to address \"" << addr << "\"";
71         throw;
72     }
73 }
74 #else
75 template <class Address>
76 template <class SPolicy>
77 prefix_ void senf::GenericAddressingPolicy<Address>::
78 connect(SocketHandle<SPolicy> handle, Address const & addr)
79 {}
80 #endif
81
82 template <class Address>
83 prefix_ void senf::GenericAddressingPolicy<Address>::local(FileHandle handle,
84                                                            Address & addr)
85 {
86     addr.clear();
87     try {
88         do_local(handle,addr.sockaddr_p(),addr.sockaddr_len());
89     } catch (Exception & e) {
90         // TODO: identify socket by some meaningful attribute
91         e << "; could not get name for address \"" << addr << "\"";
92         throw;
93     }
94 }
95
96 template <class Address>
97 prefix_ void senf::GenericAddressingPolicy<Address>::bind(FileHandle handle,
98                                                                  Address const & addr)
99 {
100     try {
101         do_bind(handle,addr.sockaddr_p(),addr.sockaddr_len());
102     } catch (Exception & e) {
103         e << "; could not bind to address \"" << addr << "\"";
104         throw;
105     }
106 }
107
108 ///////////////////////////////cti.e///////////////////////////////////////
109 #undef prefix_
110
111 \f
112 // Local Variables:
113 // mode: c++
114 // fill-column: 100
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u ../test"
119 // comment-column: 40
120 // End: