// $Id$
//
// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
//
// 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
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);
+ if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
+ throwErrno();
return std::make_pair(ling.l_onoff, ling.l_linger);
}
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)
+ throwErrno();
}
-prefix_ struct timeval senf::BSDSocketProtocol::timestamp()
+///////////////////////////////////////////////////////////////////////////
+
+prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
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_REUSEADDR,&value,&len) < 0)
+ throwErrno();
+ return value;
}
-///////////////////////////////////////////////////////////////////////////
+prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
+ const
+{
+ int ivalue (value);
+ if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
+ throwErrno();
+}
-prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
+prefix_ boost::uint8_t senf::AddressableBSDSocketProtocol::priority()
const
{
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_PRIORITY,&value,&len) < 0)
+ throwErrno();
return value;
}
-prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
+prefix_ void senf::AddressableBSDSocketProtocol::priority(boost::uint8_t 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_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
+ throwErrno();
+}
+
+prefix_ unsigned senf::AddressableBSDSocketProtocol::rcvbuf()
+ const
+{
+ unsigned size;
+ socklen_t len (sizeof(size));
+ if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
+ throwErrno();
+ // 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)
+ const
+{
+ if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
+ throwErrno();
+}
+
+prefix_ unsigned senf::AddressableBSDSocketProtocol::sndbuf()
+ const
+{
+ unsigned size;
+ socklen_t len (sizeof(size));
+ if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
+ throwErrno();
+ // 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)
+ const
+{
+ if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
+ throwErrno();
}
-///////////////////////////////cc.e////////////////////////////////////////
+/////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "BSDSocketProtocol.mpp"