X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FBSDSocketProtocol.cc;h=cfd06b5eb57fdc4591fe5016664efcde62bc1009;hb=3cb0a2ff50b8f1111da34b696e64fb1b037cd683;hp=a0512378984dcb709591287d10c3c5cb19e3f65d;hpb=1d247d12d1759ffd77f456efe3a52f03dd289994;p=senf.git diff --git a/Socket/Protocols/BSDSocketProtocol.cc b/Socket/Protocols/BSDSocketProtocol.cc index a051237..cfd06b5 100644 --- a/Socket/Protocols/BSDSocketProtocol.cc +++ b/Socket/Protocols/BSDSocketProtocol.cc @@ -43,7 +43,7 @@ prefix_ std::pair senf::BSDSocketProtocol::linger() socklen_t len = sizeof(ling); ::memset(&ling,sizeof(ling),0); if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return std::make_pair(ling.l_onoff, ling.l_linger); } @@ -54,83 +54,93 @@ prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout) ling.l_onoff = enable; ling.l_linger = timeout; if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } -/////////////////////////////////////////////////////////////////////////// - -prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr() +prefix_ boost::uint8_t senf::BSDSocketProtocol::priority() const { int value; socklen_t len (sizeof(value)); - if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0) - throw SystemException(); + if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } -prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value) +prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value) const { int ivalue (value); - if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(); -} - -prefix_ boost::uint8_t senf::AddressableBSDSocketProtocol::priority() - const -{ - int value; - socklen_t len (sizeof(value)); - if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0) - throw SystemException(); - return value; + if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); } -prefix_ void senf::AddressableBSDSocketProtocol::priority(boost::uint8_t value) +prefix_ int senf::BSDSocketProtocol::error() const { - int ivalue (value); - if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(); + 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::AddressableBSDSocketProtocol::rcvbuf() +prefix_ unsigned senf::BSDSocketProtocol::rcvbuf() const { unsigned size; socklen_t len (sizeof(size)); if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0) - throw SystemException(); + 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::AddressableBSDSocketProtocol::rcvbuf(unsigned size) +prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size) const { if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } -prefix_ unsigned senf::AddressableBSDSocketProtocol::sndbuf() +prefix_ unsigned senf::BSDSocketProtocol::sndbuf() const { unsigned size; socklen_t len (sizeof(size)); if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0) - throw SystemException(); + 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::AddressableBSDSocketProtocol::sndbuf(unsigned size) +prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size) const { if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); +} + +/////////////////////////////////////////////////////////////////////////// + +prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr() + const +{ + int value; + socklen_t len (sizeof(value)); + if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); + return value; +} + +prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value) + const +{ + int ivalue (value); + if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0) + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////cc.e////////////////////////////////////////