616557c3b9d9f7890a0f9927553e2184da7174cc
[senf.git] / Socket / Protocols / BSDSocketProtocol.hh
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 BSDSocketProtocol public header */
25
26 #ifndef HH_BSDSocketProtocol_
27 #define HH_BSDSocketProtocol_ 1
28
29 // Custom includes
30 #include "../../Socket/SocketProtocol.hh"
31 #include <boost/cstdint.hpp>
32
33 //#include "BSDSocketProtocol.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37
38     /// \addtogroup protocol_facets_group
39     /// @{
40
41     /** \brief Protocol facet providing basic BSD socket functionality
42
43         BSDSocketProtocol provides the basic BSD socket API as shared by all BSD sockets.
44      */
45     class BSDSocketProtocol
46         : public virtual SocketProtocol
47     {
48     public:
49         std::pair<bool,unsigned> linger() const; ///< Return current linger status
50                                         /**< The value is returned in an std:pair. the first element
51                                              is \c true, if linger is active. The second value is
52                                              the linger timeout in seconds.
53                                              \returns linger state (enable disabled) and linger
54                                              timeout */
55         void linger(bool enable, unsigned timeout=0) const; ///< Change linger status
56                                         /**< If linger is enabled, the timeout value specifies, how
57                                              long to wait before returning while data is unsent in
58                                              seconds. If this value is 0, a close() might wait
59                                              forever.
60                                              \param[in] enable \c true to activate linger
61                                              \param[in] timeout linger timeout in seconds */
62
63     };
64
65     /** \brief Protocol facet providing basic connection oriented BSD socket functions
66
67         AddressableBSDSocketProtocol provides the BSD socket API as it generically applies to
68         addressable (connection oriented) sockets.
69      */
70     class AddressableBSDSocketProtocol
71         : public virtual SocketProtocol
72     {
73     public:
74         bool reuseaddr() const;         ///< Return current reuseaddr state
75                                         /**< \returns \c true if \c SO_REUSEADDR is currently
76                                              enabled, \c false otherwise*/
77         void reuseaddr(bool value) const; ///< Set reuseraddr state
78                                         /**< A \c true value enables \c SO_REUSEADDR, \c false will
79                                              disable it.
80                                              \param[in] value new \c SO_REUSEADDR state */
81
82         boost::uint8_t priority() const;  ///< Get packet priority assigned to outgoing packets
83                                         /**< This call will return the priority value assigned to
84                                              packets sent via this socket. Depending on the
85                                              protocol, this value may also be placed inside the
86                                              packet headers (for IPv4, this is the TOS value).
87                                              \returns current socket priority */
88         void priority(boost::uint8_t value) const; ///< Set packet priority (e.g. TOS)
89                                         /**< Changes the packet queueing priority. Additionally may
90                                              set protocol specific options. For IPv4 sockets, it
91                                              sets the TOS field.
92                                              \param[in] value new socket priority */
93
94         unsigned rcvbuf() const;        ///< Check receive buffer size
95                                         /**< \returns size of receive buffer in bytes 
96                                              \internal Linux doubles the buffer size internally when
97                                                  changing it to cater for additional space needed by
98                                                  the linux kernel. This call will therefore return
99                                                  only half the value reported by the kernel. */
100         void rcvbuf(unsigned size) const; ///< Change receive buffer size
101                                         /**< \param[in] size new receive buffer size */
102
103         unsigned sndbuf() const;        ///< Check send buffer size
104                                         /**< \returns size of send buffer in bytes 
105                                              \internal Linux doubles the buffer size internally when
106                                                  changing it to cater for additional space needed by
107                                                  the linux kernel. This call will therefore return
108                                                  only half the value reported by the kernel. */
109         void sndbuf(unsigned size) const; ///< Change size of send buffer
110                                         /**< \param[in] size new send buffer size */
111         
112     };
113
114     /// @}
115
116 }
117
118
119 ///////////////////////////////hh.e////////////////////////////////////////
120 //#include "BSDSocketProtocol.cci"
121 //#include "BSDSocketProtocol.ct"
122 //#include "BSDSocketProtocol.cti"
123 //#include "BSDSocketProtocol.mpp"
124 #endif
125
126 \f
127 // Local Variables:
128 // mode: c++
129 // fill-column: 100
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"
134 // comment-column: 40
135 // End: