Fix SCons 1.2.0 build failure
[senf.git] / Socket / Protocols / BSDSocketProtocol.cc
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 non-inline non-template implementation */
25
26 #include "BSDSocketProtocol.hh"
27 //#include "BSDSocketProtocol.ih"
28
29 // Custom includes
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <sys/ioctl.h>
33 #include "../../Socket/SocketHandle.hh"
34
35 //#include "BSDSocketProtocol.mpp"
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 prefix_ std::pair<bool,unsigned> senf::BSDSocketProtocol::linger()
40     const
41 {
42     struct linger ling;
43     socklen_t len = sizeof(ling);
44     ::memset(&ling, 0, sizeof(ling));
45     if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
46         SENF_THROW_SYSTEM_EXCEPTION("");
47     return std::make_pair(ling.l_onoff, ling.l_linger);
48 }
49
50 prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
51     const
52 {
53     struct linger ling;
54     ling.l_onoff = enable;
55     ling.l_linger = timeout;
56     if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
57         SENF_THROW_SYSTEM_EXCEPTION("");
58 }
59
60 prefix_ boost::uint8_t senf::BSDSocketProtocol::priority()
61     const
62 {
63     int value;
64     socklen_t len (sizeof(value));
65     if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
66         SENF_THROW_SYSTEM_EXCEPTION("");
67     return value;
68 }
69
70 prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value)
71     const
72 {
73     int ivalue (value);
74     if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
75         SENF_THROW_SYSTEM_EXCEPTION("");
76 }
77
78 prefix_ int senf::BSDSocketProtocol::error()
79     const
80 {
81     int err;
82     socklen_t len (sizeof(err));
83     if (::getsockopt(fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
84         SENF_THROW_SYSTEM_EXCEPTION("");
85     return err;
86 }
87
88 prefix_ unsigned senf::BSDSocketProtocol::rcvbuf()
89     const
90 {
91     unsigned size;
92     socklen_t len (sizeof(size));
93     if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
94         SENF_THROW_SYSTEM_EXCEPTION("");
95     // Linux doubles the bufer size on setting the RCVBUF to cater for internal
96     // headers. We fix this up here .. (see lkml FAQ)
97     return size/2;
98 }
99
100 prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size)
101     const
102 {
103     if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
104         SENF_THROW_SYSTEM_EXCEPTION("");
105 }
106
107 prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
108     const
109 {
110     unsigned size;
111     socklen_t len (sizeof(size));
112     if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
113         SENF_THROW_SYSTEM_EXCEPTION("");
114     // Linux doubles the bufer size on setting the SNDBUF to cater for internal
115     // headers. We fix this up here .. (see lkml FAQ)
116     return size/2;
117 }
118
119 prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size)
120     const
121 {
122     if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
123         SENF_THROW_SYSTEM_EXCEPTION("");
124 }
125
126 ///////////////////////////////////////////////////////////////////////////
127
128 prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
129     const
130 {
131     int value;
132     socklen_t len (sizeof(value));
133     if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
134         SENF_THROW_SYSTEM_EXCEPTION("");
135     return value;
136 }
137
138 prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
139     const
140 {
141     int ivalue (value);
142     if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
143         SENF_THROW_SYSTEM_EXCEPTION("");
144 }
145
146 /////////////////////////////cc.e////////////////////////////////////////
147 #undef prefix_
148 //#include "BSDSocketProtocol.mpp"
149
150
151 // Local Variables:
152 // mode: c++
153 // fill-column: 100
154 // c-file-style: "senf"
155 // indent-tabs-mode: nil
156 // ispell-local-dictionary: "american"
157 // compile-command: "scons -u test"
158 // comment-column: 40
159 // End: