4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief BSDSocketProtocol non-inline non-template implementation */
31 #include "BSDSocketProtocol.hh"
32 //#include "BSDSocketProtocol.ih"
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <sys/ioctl.h>
39 //#include "BSDSocketProtocol.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 prefix_ std::pair<bool,unsigned> senf::BSDSocketProtocol::linger()
47 socklen_t len = sizeof(ling);
48 ::memset(&ling, 0, sizeof(ling));
49 if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
50 SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_LINGER");
51 return std::make_pair(ling.l_onoff, ling.l_linger);
54 prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
58 ling.l_onoff = enable;
59 ling.l_linger = timeout;
60 if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
61 SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_LINGER");
64 prefix_ boost::uint8_t senf::BSDSocketProtocol::priority()
68 socklen_t len (sizeof(value));
69 if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
70 SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_PRIORITY");
74 prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value)
78 if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
79 SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_PRIORITY");
82 prefix_ int senf::BSDSocketProtocol::error()
86 socklen_t len (sizeof(err));
87 if (::getsockopt(fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
88 SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_ERROR");
92 prefix_ unsigned senf::BSDSocketProtocol::rcvbuf()
96 socklen_t len (sizeof(size));
97 if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
98 SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_RCVBUF");
99 // Linux doubles the bufer size on setting the RCVBUF to cater for internal
100 // headers. We fix this up here .. (see lkml FAQ)
104 prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size)
107 if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
108 SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_RCVBUF");
111 prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
115 socklen_t len (sizeof(size));
116 if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
117 SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_SNDBUF");
118 // Linux doubles the bufer size on setting the SNDBUF to cater for internal
119 // headers. We fix this up here .. (see lkml FAQ)
123 prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size)
126 if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
127 SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_SNDBUF");
130 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
136 socklen_t len (sizeof(value));
137 if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
138 SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_REUSEADDR");
142 prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
146 if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
147 SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_REUSEADDR");
150 //-/////////////////////////////////////////////////////////////////////////////////////////////////
152 //#include "BSDSocketProtocol.mpp"
158 // c-file-style: "senf"
159 // indent-tabs-mode: nil
160 // ispell-local-dictionary: "american"
161 // compile-command: "scons -u test"
162 // comment-column: 40