4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief BSDSocketProtocol non-inline non-template implementation */
26 #include "BSDSocketProtocol.hh"
27 //#include "BSDSocketProtocol.ih"
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <sys/ioctl.h>
33 #include "../../Socket/SocketHandle.hh"
35 //#include "BSDSocketProtocol.mpp"
37 ///////////////////////////////cc.p////////////////////////////////////////
39 prefix_ std::pair<bool,unsigned> senf::BSDSocketProtocol::linger()
43 socklen_t len = sizeof(ling);
44 ::memset(&ling,sizeof(ling),0);
45 if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
47 return std::make_pair(ling.l_onoff, ling.l_linger);
50 prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
54 ling.l_onoff = enable;
55 ling.l_linger = timeout;
56 if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
60 ///////////////////////////////////////////////////////////////////////////
62 prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
66 socklen_t len (sizeof(value));
67 if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
72 prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
76 if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
80 prefix_ boost::uint8_t senf::AddressableBSDSocketProtocol::priority()
84 socklen_t len (sizeof(value));
85 if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
90 prefix_ void senf::AddressableBSDSocketProtocol::priority(boost::uint8_t value)
94 if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
98 prefix_ unsigned senf::AddressableBSDSocketProtocol::rcvbuf()
102 socklen_t len (sizeof(size));
103 if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
105 // Linux doubles the bufer size on setting the RCVBUF to cater for internal
106 // headers. We fix this up here .. (see lkml FAQ)
110 prefix_ void senf::AddressableBSDSocketProtocol::rcvbuf(unsigned size)
113 if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
117 prefix_ unsigned senf::AddressableBSDSocketProtocol::sndbuf()
121 socklen_t len (sizeof(size));
122 if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
124 // Linux doubles the bufer size on setting the SNDBUF to cater for internal
125 // headers. We fix this up here .. (see lkml FAQ)
129 prefix_ void senf::AddressableBSDSocketProtocol::sndbuf(unsigned size)
132 if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
136 /////////////////////////////cc.e////////////////////////////////////////
138 //#include "BSDSocketProtocol.mpp"
144 // c-file-style: "senf"
145 // indent-tabs-mode: nil
146 // ispell-local-dictionary: "american"
147 // compile-command: "scons -u test"
148 // comment-column: 40