prefix_ void senf::FileBody::v_close()
{
if (::close(fd_) != 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not ::close FileBody fd");
}
prefix_ void senf::FileBody::v_terminate()
const
{
int flags = ::fcntl(fd(),F_GETFL);
- if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("");
+ if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("::fcntl(F_GETFL)");
return ! (flags & O_NONBLOCK);
}
prefix_ void senf::FileBody::blocking(bool status)
{
int flags = ::fcntl(fd(),F_GETFL);
- if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("");
+ if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("::fcntl(F_GETFL)");
if (status) flags &= ~O_NONBLOCK;
else flags |= O_NONBLOCK;
- if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION("");
+ if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION("::fcntl(F_SETFL)");
}
/* We don't take POLLIN/POLLOUT as argument to avoid having to include
case EINTR:
break;
default:
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not check ::poll");
}
} while (rv<0);
return rv>0;
socklen_t * len)
{
if (::getsockname(handle.fd(),addr,len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get sockname");
}
prefix_ void senf::BSDAddressingPolicyMixinBase::do_peer(FileHandle const & handle,
socklen_t * len)
{
if (::getpeername(handle.fd(),addr,len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get peername");
}
prefix_ void senf::BSDAddressingPolicyMixinBase::do_bind(FileHandle const & handle,
socklen_t len)
{
if (::bind(handle.fd(),addr,len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not bind");
}
prefix_ void senf::BSDAddressingPolicyMixinBase::do_connect(FileHandle const & handle,
int err = 0;
socklen_t len = sizeof(err);
if (::getsockopt(handle.fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_ERROR)");
if (err != 0)
throw SystemException(err SENF_EXC_DEBUGINFO);
return;
case EINTR:
break;
default:
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not ::connect");
}
else
return;
socklen_t len = sizeof(ling);
::memset(&ling, 0, sizeof(ling));
if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_LINGER");
return std::make_pair(ling.l_onoff, ling.l_linger);
}
ling.l_onoff = enable;
ling.l_linger = timeout;
if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_LINGER");
}
prefix_ boost::uint8_t senf::BSDSocketProtocol::priority()
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_PRIORITY");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_PRIORITY");
}
prefix_ int senf::BSDSocketProtocol::error()
int err;
socklen_t len (sizeof(err));
if (::getsockopt(fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_ERROR");
return err;
}
unsigned size;
socklen_t len (sizeof(size));
if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_RCVBUF");
// 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;
const
{
if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_RCVBUF");
}
prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
unsigned size;
socklen_t len (sizeof(size));
if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_SNDBUF");
// 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;
const
{
if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_SNDBUF");
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_REUSEADDR");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_REUSEADDR");
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
const
{
if (::ioctl(fd(), DMX_SET_BUFFER_SIZE, size) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("")
- << "Could not set the size of the buffer on DVB adapter. requested size: "
- << size << ".";
+ SENF_THROW_SYSTEM_EXCEPTION(
+ "Could not set the size of the buffer on DVB adapter. requested size: ")
+ << size << ".";
}
prefix_ void senf::DVBDemuxSocketProtocol::startFiltering()
string devFrontend = str( boost::format("/dev/dvb/adapter%d/frontend%d") % adapter % device);
int f = open(devFrontend.c_str(), flags);
if (f < 0)
- SENF_THROW_SYSTEM_EXCEPTION("")<< "Could not open frontend device of DVB adapter " << devFrontend << ".";
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open frontend device of DVB adapter ") << devFrontend << ".";
fd(f);
}
{
// tuning
if (::ioctl(fd(), FE_SET_FRONTEND, &frontend) )
- SENF_THROW_SYSTEM_EXCEPTION("") << "ioctl FE_SET_FRONTEND failed. Socket should initialized with r/w permissions.";;
+ SENF_THROW_SYSTEM_EXCEPTION("ioctl FE_SET_FRONTEND failed. Socket should initialized with r/w permissions.");
}
prefix_ void senf::DVBFrontendSocketProtocol::tuneDVB_T(unsigned int frequency,
::memset(&info, 0, sizeof(struct dvb_frontend_info));
if (::ioctl(fd(), FE_GET_INFO, &info)) {
- SENF_THROW_SYSTEM_EXCEPTION("") << "Could not read on fildescriptor.";
+ SENF_THROW_SYSTEM_EXCEPTION("Could not read on fildescriptor.");
}
return info;
}
{
struct timeval tv;
if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get timestamp in DatagramSocketProtocol");
return ClockService::from_timeval(tv);
}
{
int sock = ::socket(PF_INET, SOCK_RAW, protocol);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open ConnectedRawV4Socket");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open ConnectedRawV6Socket");
fd(sock);
}
int value (0);
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_LOOP)");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_LOOP)");
}
prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface)
throw SystemException(EINVAL SENF_EXC_DEBUGINFO);
}
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_IF)");
}
prefix_ unsigned senf::MulticastSocketProtocol::mcTTL()
int value (0);
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_TTL)");
return value;
}
const
{
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_TTL");
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr,
mreqn.imr_address.s_addr = localAddr.inaddr();
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr,
if (mreqn.imr_ifindex == 0)
throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
}
namespace {
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
}
else {
struct ipv6_mreq mreqn;
std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
mreqn.ipv6mr_interface = 0;
if (::setsockopt(fd(),SOL_IPV6,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_DROP_MEMBERSHIP");
}
}
if (mreqn.imr_ifindex == 0)
throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
}
else {
struct ipv6_mreq mreqn;
if (mreqn.ipv6mr_interface == 0)
throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IPV6,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_DROP_MEMBERSHIP");
}
}
{
int sock = ::socket(PF_INET, SOCK_RAW, protocol);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open RawV4Socket");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open RawV6Socket");
fd(sock);
}
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not call ::ioctl(SIOCINQ) in RawINetSocketProtocol::available()");
return n;
}
{
int sock = ::socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv4Socket");
fd(sock);
}
{
int sock = ::socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv4Socket");
fd(sock);
}
reuseaddr(true);
serverHandle().bind(address);
if (::listen(fd(),backlog) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not listen on TCPv4Socket");
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
{
int sock = ::socket(PF_INET6,SOCK_STREAM,0);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv6Socket");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_STREAM,0);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv6Socket");
fd(sock);
}
serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not listen on TCPv6Socket");
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not get sockopt TCP_NODELAY");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not set sockopt TCP_NODELAY");
}
prefix_ unsigned senf::TCPSocketProtocol::siocinq()
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::ioctl(SIOCINQ)");
return n;
}
{
int n;
if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::ioctl(SIOCOUTQ)");
return n;
}
{
int sock = ::socket(PF_INET,SOCK_DGRAM,0);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open UDPv4Socket");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
if (sock < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not open UDPv6Socket");
fd(sock);
}
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("could not call ::ioctl(SIOCINQ) in UDPSocketProtocol::available()");
return n;
}
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2011
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+// http://senf.berlios.de/license.html
+//
+// The Fraunhofer FOKUS Public License Version 1.0 is based on,
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+// Thorsten Horstmann <tho@berlios.de>
+
+/** \file
+ \brief MmapedPacketSocketProtocol and MmapedPacketSocketHandle non-inline non-template implementation
+ */
+
+#include "MmapedPacketSocketHandle.hh"
+//#include "MmapedPacketSocketHandle.ih"
+
+// Custom includes
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/mman.h>
+#include <linux/if_packet.h>
+#include <net/ethernet.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <errno.h>
+
+//#include "MmapedPacketSocketHandle.mpp"
+#define prefix_
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+prefix_ void senf::MmapedPacketSocketProtocol::init_client(SocketType type, int protocol)
+{
+ /* Setup req */
+ req_.tp_block_size = 4096;
+ req_.tp_frame_size = 2048;
+ req_.tp_block_nr = 32;
+ req_.tp_frame_nr = 2*32;
+ /* Setup socket */
+ int socktype = (type == RawSocket ? SOCK_RAW : SOCK_DGRAM);
+ if (protocol == -1)
+ protocol = ETH_P_ALL;
+ int sock = ::socket(PF_PACKET, socktype, htons(protocol));
+ if (sock < 0)
+ SENF_THROW_SYSTEM_EXCEPTION("::socket(...) failed.");
+ if ( (setsockopt(sock, SOL_PACKET, PACKET_RX_RING, reinterpret_cast<char *>(&req_), sizeof(req_))) != 0 )
+ SENF_THROW_SYSTEM_EXCEPTION("setsockopt(PACKET_RX_RING) failed.");
+ /* Setup mmap */
+ map_ = static_cast<char *>(
+ mmap( NULL, req_.tp_block_size * req_.tp_block_nr, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, sock, 0));
+ if ( map_ == MAP_FAILED )
+ SENF_THROW_SYSTEM_EXCEPTION("mmap failed.");
+ /* Setup our ringbuffer */
+ ring_.resize( req_.tp_frame_nr);
+ for (unsigned i=0; i<req_.tp_frame_nr; i++) {
+ ring_[i].iov_base = (void *) (&map_[i*req_.tp_frame_size]);
+ ring_[i].iov_len = req_.tp_frame_size;
+ }
+ fd( sock);
+}
+
+prefix_ unsigned senf::MmapedPacketSocketProtocol::available()
+ const
+{
+
+}
+
+prefix_ bool senf::MmapedPacketSocketProtocol::eof()
+ const
+{
+ return false;
+}
+
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+#undef prefix_
+//#include "PacketSocketHandle.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
--- /dev/null
+// $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
+//
+// Copyright (C) 2011
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+// http://senf.berlios.de/license.html
+//
+// The Fraunhofer FOKUS Public License Version 1.0 is based on,
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+// Thorsten Horstmann <tho@berlios.de>
+
+/** \file
+ \brief MmapedPacketSocketProtocol and MmapedPacketSocketHandle public header
+ */
+
+#ifndef HH_SENF_Socket_Protocols_Raw_MmapedPacketSocketHandle_
+#define HH_SENF_Socket_Protocols_Raw_MmapedPacketSocketHandle_ 1
+
+// Custom includes
+#include <senf/Socket/SocketPolicy.hh>
+#include <senf/Socket/SocketProtocol.hh>
+#include <senf/Socket/ProtocolClientSocketHandle.hh>
+#include <senf/Socket/FramingPolicy.hh>
+#include <senf/Socket/CommunicationPolicy.hh>
+#include <senf/Socket/ReadWritePolicy.hh>
+#include "LLAddressing.hh"
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+namespace senf {
+
+ /// \addtogroup concrete_protocol_group
+ //\{
+
+ typedef MakeSocketPolicy<
+ LLAddressingPolicy,
+ DatagramFramingPolicy,
+ UnconnectedCommunicationPolicy,
+ NotReadablePolicy,
+ NotWriteablePolicy
+ >::policy MmapedPacket_Policy; ///< Policy of MmapedPacketSocketProtocol
+
+
+ /** \brief
+ */
+ class MmapedPacketSocketProtocol
+ : public ConcreteSocketProtocol<MmapedPacket_Policy, MmapedPacketSocketProtocol>
+ {
+ public:
+ enum SocketType { RawSocket, DatagramSocket };
+ ///< Socket types
+
+ ///\name Constructors
+ //\{
+ void init_client(SocketType type = RawSocket, int protocol = -1);
+ //\}
+
+ ///\name Protocol Interface
+ //\{
+
+ //\}
+
+ ///\name Abstract Interface Implementation
+ //\{
+ unsigned available() const;
+ bool eof() const;
+ //\}
+
+ private:
+ char * map_;
+// struct iovec * ring_;
+ struct tpacket_req req_;
+ typedef std::vector<struct iovec> iovecRing;
+ iovecRing ring_;
+ };
+
+
+ typedef ProtocolClientSocketHandle<MmapedPacketSocketProtocol> MmapedPacketSocketHandle;
+ ///< SocketHandle of the MmapedPacketSocketProtocol
+ /**< \related MmapedPacketSocketProtocol */
+
+ //\}
+}
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+//#include "MmapedPacketSocketHandle.cci"
+//#include "MmapedPacketSocketHandle.ct"
+//#include "MmapedPacketSocketHandle.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2011
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+// http://senf.berlios.de/license.html
+//
+// The Fraunhofer FOKUS Public License Version 1.0 is based on,
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+// Thorsten Horstmann <tho@berlios.de>
+
+/** \file
+ \brief MmapedPacketSocketHandle unit tests */
+
+
+// Custom includes
+#include "MmapedPacketSocketHandle.hh"
+
+#include <senf/Utils/auto_unit_test.hh>
+#include <boost/test/test_tools.hpp>
+
+#define prefix_
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+SENF_AUTO_UNIT_TEST(mmapedPacketSocketHandle)
+{
+ // packet sockets are only allowed for root
+ if (getuid() != 0) {
+ BOOST_WARN_MESSAGE(false, "Cannot test senf::MmapedPacketSocketHandle as non-root user");
+ BOOST_CHECK( true );
+ return;
+ }
+
+ {
+ senf::MmapedPacketSocketHandle sock;
+
+ BOOST_CHECK( ! sock.eof() );
+ }
+}
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
#include <unistd.h>
#include <errno.h>
-
//#include "ReadWritePolicy.mpp"
#define prefix_
//-/////////////////////////////////////////////////////////////////////////////////////////////////
rv = 0;
break;
default:
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION(":::read");
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::recvfrom");
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::write");
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- SENF_THROW_SYSTEM_EXCEPTION("");
+ SENF_THROW_SYSTEM_EXCEPTION("::sendto");
}
} while (rv<0);
return rv;
if (! stdoutLog_.empty()) {
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0)
- SENF_THROW_SYSTEM_EXCEPTION("")
- << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout.";
+ SENF_THROW_SYSTEM_EXCEPTION(
+ " Could not open \"" + stdoutLog_ + "\" for redirecting stdout.");
stdout_ = fd;
}
if (! stderrLog_.empty()) {
else {
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0)
- SENF_THROW_SYSTEM_EXCEPTION("")
- << " Could not open \"" << stderrLog_ << "\" for redirecting stderr.";
+ SENF_THROW_SYSTEM_EXCEPTION(
+ " Could not open \"" + stderrLog_ + "\" for redirecting stderr.");
stderr_ = fd;
}
}
{
std::ofstream pidf (tempname.c_str());
if (! pidf)
- SENF_THROW_SYSTEM_EXCEPTION("")
- << " Could not open pidfile \"" << tempname << "\" for output.";
+ SENF_THROW_SYSTEM_EXCEPTION(" Could not open pidfile \"" + tempname + "\" for output.");
pidf << ::getpid() << std::endl;
if (! pidf)
- SENF_THROW_SYSTEM_EXCEPTION("")
- << " Could not write to pidfile \"" << tempname << "\".";
+ SENF_THROW_SYSTEM_EXCEPTION(" Could not write to pidfile \"" + tempname + "\".");
}
if (::link(tempname.c_str(), pidfile_.c_str()) < 0) {
if (errno != EEXIST)
- SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % pidfile_ % tempname;
+ SENF_THROW_SYSTEM_EXCEPTION((linkErrorFormat % pidfile_ % tempname).str());
}
else {
struct ::stat s;
LIBC_CALL( ::unlink, (tempname.c_str() ));
if (::link(pidfile_.c_str(), tempname.c_str()) < 0) {
if (errno != ENOENT)
- SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % tempname % pidfile_;
+ SENF_THROW_SYSTEM_EXCEPTION( (linkErrorFormat % tempname % pidfile_).str());
// Hmm ... the pidfile mysteriously disappeared ... try again.
continue;
}
#include <string>
#include <iostream>
#include <sstream>
-#include <boost/preprocessor/repeat.hpp>
-#include <boost/preprocessor/cat.hpp>
#include <boost/utility.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <senf/config.hh>
+#include "senfassert.hh"
+
//#include "Exception.mpp"
//-/////////////////////////////////////////////////////////////////////////////////////////////////
# define SENF_EXC_DEBUGINFO
# endif
-# define SENF_THROW_SYSTEM_EXCEPTION(desc) throw senf::SystemException(desc SENF_EXC_DEBUGINFO)
+# define SENF_THROW_SYSTEM_EXCEPTION(desc) \
+ SENF_STATIC_ASSERT( sizeof(desc) > 1, \
+ EMPTY_DESCRIPTION_FOR_SYSTEM_EXCEPTION_NOT_ALLOWED); \
+ throw senf::SystemException(desc SENF_EXC_DEBUGINFO)
}
#endif
+
+/* Lifted direct from:
+ Modern C++ Design: Generic Programming and Design Patterns Applied Section 2.1
+ by Andrei Alexandrescu
+*/
+namespace senf {
+namespace detail {
+ template<bool> class compile_time_check
+ {
+ public:
+ compile_time_check(...) {}
+ };
+
+ template<> class compile_time_check<false>
+ {
+ };
+}}
+
+ /*
+ SENF_STATIC_ASSERT is only in operation when SENF_DEBUG is defined. It will test its first
+ argument at compile time and on failure report the error message of the second argument,
+ which must be a valid c++ classname. i.e. no spaces, punctuation or reserved keywords.
+ */
+#ifdef SENF_DEBUG
+# define SENF_STATIC_ASSERT(expr, msg) \
+ do { \
+ struct STATIC_ASSERT_FAILED_##msg {}; \
+ typedef senf::detail::compile_time_check< (expr) != 0 > tmplimpl; \
+ tmplimpl aTemp = tmplimpl(STATIC_ASSERT_FAILED_##msg()); \
+ (void)sizeof(aTemp); \
+ } while (0)
+#else
+# define SENF_STATIC_ASSERT(expr, msg)
+#endif
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
//#include "senfassert.cci"
//#include "senfassert.ct"