switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / BSDSocketProtocol.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief BSDSocketProtocol public header */
30
31 #ifndef HH_SENF_Socket_Protocols_BSDSocketProtocol_
32 #define HH_SENF_Socket_Protocols_BSDSocketProtocol_ 1
33
34 // Custom includes
35 #include <senf/Socket/SocketProtocol.hh>
36 #include <boost/cstdint.hpp>
37
38 //#include "BSDSocketProtocol.mpp"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 namespace senf {
42
43     /// \addtogroup protocol_facets_group
44     //\{
45
46     /** \brief Protocol facet providing basic BSD socket functionality
47
48         BSDSocketProtocol provides the basic BSD socket API as shared by all BSD sockets.
49      */
50     class BSDSocketProtocol
51         : public virtual SocketProtocol
52     {
53     public:
54         std::pair<bool,unsigned> linger() const; ///< Return current linger status
55                                         /**< The value is returned in an std:pair. the first element
56                                              is \c true, if linger is active. The second value is
57                                              the linger timeout in seconds.
58                                              \returns linger state (enable disabled) and linger
59                                              timeout */
60         void linger(bool enable, unsigned timeout=0) const; ///< Change linger status
61                                         /**< If linger is enabled, the timeout value specifies, how
62                                              long to wait before returning while data is unsent in
63                                              seconds. If this value is 0, a close() might wait
64                                              forever.
65                                              \param[in] enable \c true to activate linger
66                                              \param[in] timeout linger timeout in seconds */
67        boost::uint8_t priority() const;  ///< Get packet priority assigned to outgoing packets
68                                         /**< This call will return the priority value assigned to
69                                              packets sent via this socket. Depending on the
70                                              protocol, this value may also be placed inside the
71                                              packet headers (for IPv4, this is the TOS value).
72                                              \returns current socket priority */
73         void priority(boost::uint8_t value) const; ///< Set packet priority (e.g. TOS)
74                                         /**< Changes the packet queueing priority. Additionally may
75                                              set protocol specific options. For IPv4 sockets, it
76                                              sets the TOS field.
77                                              \param[in] value new socket priority */
78
79         int error() const;              ///< Get and clear pending socket error
80                                         /**< This call will get <em>and clear</em> a pending socket
81                                              error. This includes asynchronous errors received via
82                                              the network (e.g. via ICMP). */
83
84         unsigned rcvbuf() const;        ///< Check receive buffer size
85                                         /**< \returns size of receive buffer in bytes
86                                              \internal Linux doubles the buffer size internally when
87                                                  changing it to cater for additional space needed by
88                                                  the linux kernel. This call will therefore return
89                                                  only half the value reported by the kernel. */
90         void rcvbuf(unsigned size) const; ///< Change receive buffer size
91                                         /**< \param[in] size new receive buffer size */
92
93         unsigned sndbuf() const;        ///< Check send buffer size
94                                         /**< \returns size of send buffer in bytes
95                                              \internal Linux doubles the buffer size internally when
96                                                  changing it to cater for additional space needed by
97                                                  the linux kernel. This call will therefore return
98                                                  only half the value reported by the kernel. */
99         void sndbuf(unsigned size) const; ///< Change size of send buffer
100                                         /**< \param[in] size new send buffer size */
101
102      };
103
104     /** \brief Protocol facet providing basic connection oriented BSD socket functions
105
106         AddressableBSDSocketProtocol provides the BSD socket API as it generically applies to
107         addressable (connection oriented) sockets.
108      */
109     class AddressableBSDSocketProtocol
110         : public virtual SocketProtocol
111     {
112     public:
113         bool reuseaddr() const;         ///< Return current reuseaddr state
114                                         /**< \returns \c true if \c SO_REUSEADDR is currently
115                                              enabled, \c false otherwise*/
116         void reuseaddr(bool value) const; ///< Set reuseraddr state
117                                         /**< A \c true value enables \c SO_REUSEADDR, \c false will
118                                              disable it.
119                                              \param[in] value new \c SO_REUSEADDR state */
120     };
121
122     //\}
123
124 }
125
126
127 //-/////////////////////////////////////////////////////////////////////////////////////////////////
128 //#include "BSDSocketProtocol.cci"
129 //#include "BSDSocketProtocol.ct"
130 //#include "BSDSocketProtocol.cti"
131 //#include "BSDSocketProtocol.mpp"
132 #endif
133
134 \f
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // comment-column: 40
143 // End: