X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FBSDSocketProtocol.cc;h=4524cae47bc65508adc3528b5f2092166a530a8f;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=cd30a737d0f1392199258c99b539837a8f26bad7;hpb=8d2d26f114d3df0a60c5c516fcf40671b1e55558;p=senf.git diff --git a/Socket/Protocols/BSDSocketProtocol.cc b/Socket/Protocols/BSDSocketProtocol.cc index cd30a73..4524cae 100644 --- a/Socket/Protocols/BSDSocketProtocol.cc +++ b/Socket/Protocols/BSDSocketProtocol.cc @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -41,9 +41,9 @@ prefix_ std::pair senf::BSDSocketProtocol::linger() { struct linger ling; socklen_t len = sizeof(ling); - ::memset(&ling,sizeof(ling),0); - if (::getsockopt(body().fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0) - throw SystemException(errno); + ::memset(&ling, 0, sizeof(ling)); + if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); return std::make_pair(ling.l_onoff, ling.l_linger); } @@ -53,17 +53,74 @@ prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout) struct linger ling; ling.l_onoff = enable; ling.l_linger = timeout; - if (::setsockopt(body().fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0) - throw SystemException(errno); + if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); } -prefix_ struct timeval senf::BSDSocketProtocol::timestamp() +prefix_ boost::uint8_t senf::BSDSocketProtocol::priority() const { - struct timeval tv; - if (::ioctl(body().fd(), SIOCGSTAMP, &tv) < 0) - throw SystemException(errno); - return tv; + int value; + socklen_t len (sizeof(value)); + if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); + return value; +} + +prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value) + const +{ + int ivalue (value); + if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); +} + +prefix_ int senf::BSDSocketProtocol::error() + const +{ + int err; + socklen_t len (sizeof(err)); + if (::getsockopt(fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); + return err; +} + +prefix_ unsigned senf::BSDSocketProtocol::rcvbuf() + const +{ + unsigned size; + socklen_t len (sizeof(size)); + if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); + // Linux doubles the bufer size on setting the RCVBUF to cater for internal + // headers. We fix this up here .. (see lkml FAQ) + return size/2; +} + +prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size) + const +{ + if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); +} + +prefix_ unsigned senf::BSDSocketProtocol::sndbuf() + const +{ + unsigned size; + socklen_t len (sizeof(size)); + if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); + // Linux doubles the bufer size on setting the SNDBUF to cater for internal + // headers. We fix this up here .. (see lkml FAQ) + return size/2; +} + +prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size) + const +{ + if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////////////////////////////////////////////////// @@ -73,8 +130,8 @@ prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr() { int value; socklen_t len (sizeof(value)); - if (::getsockopt(body().fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0) - throw SystemException(errno); + if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } @@ -82,15 +139,15 @@ prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value) const { int ivalue (value); - if (::setsockopt(body().fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(errno); + if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); } -///////////////////////////////cc.e//////////////////////////////////////// +/////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "BSDSocketProtocol.mpp" - + // Local Variables: // mode: c++ // fill-column: 100