senf::TransportPacket p (senf::TransportPacket::create(data));
- BOOST_CHECK_EQUAL( p->sync_byte(), TransportPacketType::SYNC_BYTE );
- BOOST_CHECK( ! p->transport_error_indicator() );
- BOOST_CHECK( p->pusi() );
- BOOST_CHECK( ! p->transport_priority() );
- BOOST_CHECK_EQUAL( p->pid(), 0x010fu );
- BOOST_CHECK_EQUAL( p->transport_scrmbl_ctrl(), 0x0u );
- BOOST_CHECK_EQUAL( p->adaptation_field_ctrl(), 0x1u );
- BOOST_CHECK_EQUAL( p->continuity_counter(), 0x0eu );
+ BOOST_CHECK_EQUAL( p->sync_byte(), TransportPacketType::SYNC_BYTE+0 );
+ BOOST_CHECK( ! p->transport_error_indicator() );
+ BOOST_CHECK( p->pusi() );
+ BOOST_CHECK( ! p->transport_priority() );
+ BOOST_CHECK_EQUAL( p->pid(), 0x010fu );
+ BOOST_CHECK_EQUAL( p->transport_scrmbl_ctrl(), 0x0u );
+ BOOST_CHECK_EQUAL( p->adaptation_field_ctrl(), 0x1u );
+ BOOST_CHECK_EQUAL( p->continuity_counter(), 0x0eu );
}
///////////////////////////////cc.e////////////////////////////////////////
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-#define CheckError(op,args) if (op args < 0) throw SystemException(# op, errno)
+#define CheckError(op,args) if (op args < 0) SENF_THROW_SYSTEM_EXCEPTION(# op)
///////////////////////////////////////////////////////////////////////////
// senf::ClockService::Impl
{
try {
if (event != senf::Scheduler::EV_READ)
- throw SystemException(EPIPE);
+ throw SystemException(EPIPE SENF_EXC_DEBUGINFO);
std::string rcv;
handle.read(rcv, maxSize_ - data_.size());
data_.append(rcv);
prefix_ void senf::ReadHelper<Handle>::throw_error()
const
{
- if (errno_ != 0) throw SystemException(errno_);
+ if (errno_ != 0) throw SystemException(errno_ SENF_EXC_DEBUGINFO);
}
///////////////////////////////cti.e///////////////////////////////////////
eventTime_(0), eventEarly_(ClockService::milliseconds(11)), eventAdjust_(0)
{
if (epollFd_<0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
if (::pipe(sigpipe_) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
int flags (::fcntl(sigpipe_[1],F_GETFL));
if (flags < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
flags |= O_NONBLOCK;
if (::fcntl(sigpipe_[1], F_SETFL, flags) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
::epoll_event ev;
::memset(&ev, 0, sizeof(ev));
ev.events = EV_READ;
ev.data.fd = sigpipe_[0];
if (::epoll_ctl(epollFd_, EPOLL_CTL_ADD, sigpipe_[0], &ev) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::Scheduler::registerSignal(unsigned signal, SimpleCallback const & cb)
++ files_;
}
else
- throw SystemException("::epoll_ctl()");
+ SENF_THROW_SYSTEM_EXCEPTION("::epoll_ctl()");
}
}
}
if (! file && epoll_ctl(epollFd_, action, fd, &ev) < 0)
- throw SystemException("::epoll_ctl()");
+ SENF_THROW_SYSTEM_EXCEPTION("::epoll_ctl()");
if (file)
-- files_;
}
if (signal == SIGCHLD)
sa.sa_flags |= SA_NOCLDSTOP;
if (::sigaction(signal, &sa, 0) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
}
}
if (events<0)
if (errno != EINTR)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
eventTime_ = ClockService::now();
bool complete_ (false);
try {
if (event != senf::Scheduler::EV_WRITE)
- throw SystemException(EPIPE);
+ throw SystemException(EPIPE SENF_EXC_DEBUGINFO);
offset_ = handle.write(std::make_pair(offset_,data_.end()));
if (offset_ == data_.end()) {
data_.erase();
const
{
if (errno_ != 0)
- throw SystemException(errno_);
+ throw SystemException(errno_ SENF_EXC_DEBUGINFO);
}
case EINTR:
break;
default:
- throw SystemException("ConnectedCommunicationPolicy::do_accept failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("ConnectedCommunicationPolicy::do_accept failed.");
}
} while (rv<0);
return rv;
prefix_ void senf::FileBody::close()
{
if (!valid())
- throw SystemException(EBADF);
+ throw SystemException(EBADF SENF_EXC_DEBUGINFO);
v_close();
fd_ = -1;
}
prefix_ void senf::FileBody::v_close()
{
if (::close(fd_) != 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::FileBody::v_terminate()
const
{
int flags = ::fcntl(fd(),F_GETFL);
- if (flags < 0) throw SystemException();
+ if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("");
return ! (flags & O_NONBLOCK);
}
prefix_ void senf::FileBody::blocking(bool status)
{
int flags = ::fcntl(fd(),F_GETFL);
- if (flags < 0) throw SystemException();
+ if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("");
if (status) flags &= ~O_NONBLOCK;
else flags |= O_NONBLOCK;
- if (::fcntl(fd(), F_SETFL, flags) < 0) throw SystemException();
+ if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION("");
}
/* We don't take POLLIN/POLLOUT as argument to avoid having to include
case EINTR:
break;
default:
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
} while (rv<0);
return rv>0;
{
sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0);
if ( sockfd_ < 0)
- throw SystemException("Could not open socket for NetdeviceController.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open socket for NetdeviceController.");
}
prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr)
::memset( &ifr, 0, sizeof(ifr));
ifr.ifr_ifindex = ifindex_;
if ( ::ioctl( sockfd_, SIOCGIFNAME, &ifr ) < 0 )
- throw SystemException("NetdeviceController")
+ SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController")
<< " could not discover the name of the interface with index " << ifindex_ << ".";
}
const
{
if ( ::ioctl( sockfd_, request, &ifr ) < 0 )
- throw SystemException("NetdeviceController::doIoctl failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController::doIoctl failed.");
}
///////////////////////////////cc.e////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(NetdeviceController) {
- senf::NetdeviceController ctrl ("wlan0");
+ senf::NetdeviceController ctrl ("lo");
std::cout << "name: " << ctrl.interfaceName() << "\n";
senf::MACAddress oldAddr(ctrl.hardwareAddress());
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);
}
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_ boost::uint8_t senf::BSDSocketProtocol::priority()
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ unsigned senf::BSDSocketProtocol::rcvbuf()
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;
const
{
if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
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;
const
{
if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
///////////////////////////////////////////////////////////////////////////
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
/////////////////////////////cc.e////////////////////////////////////////
"/dev/dvb/adapter%d/demux%d") % adapter % device);
int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0){
- throw SystemException("Could not open demux device of DVB adapter ") << devDemux << ".";
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
}
fd(f);
}
const
{
if (::ioctl(fd(), DMX_SET_FILTER, filter) < 0)
- throw SystemException("Could not set section filter of DVB adapter.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not set section filter of DVB adapter.");
}
// ----------------------------------------------------------------
"/dev/dvb/adapter%d/demux%d") % adapter % device);
int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throw SystemException( "Could not open demux device of DVB adapter ") << devDemux << ".";
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
fd(f);
}
const
{
if (::ioctl(fd(), DMX_SET_PES_FILTER, filter) < 0)
- throw SystemException("Could not set PES filter of DVB adapter.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not set PES filter of DVB adapter.");
}
// ----------------------------------------------------------------
"/dev/dvb/adapter%d/dvr%d") % adapter % device);
int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throw SystemException( "Could not open dvr device of DVB adapter ") << devDvr << ".";
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open dvr device of DVB adapter ") << devDvr << ".";
fd(f);
}
const
{
if (::ioctl(fd(), DMX_SET_BUFFER_SIZE, size) < 0)
- throw SystemException()
+ SENF_THROW_SYSTEM_EXCEPTION("")
<< "Could not set the size of the buffer on DVB adapter. requested size: "
<< size << ".";
}
const
{
if (::ioctl(fd(), DMX_START) < 0)
- throw SystemException("Could not start filtering operation on DVB adapter.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not start filtering operation on DVB adapter.");
}
prefix_ void senf::DVBDemuxSocketProtocol::stopFiltering()
const
{
if (::ioctl(fd(), DMX_STOP) < 0)
- throw SystemException("Could not stop filtering operation on DVB adapter.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not stop filtering operation on DVB adapter.");
}
prefix_ bool senf::DVBDemuxSocketProtocol::eof()
"/dev/dvb/adapter%d/frontend%d") % adapter % device);
int f = open(devFrontend.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throw SystemException() << "Could not open frontend device of DVB adapter " << devFrontend << ".";
+ SENF_THROW_SYSTEM_EXCEPTION("") << "Could not open frontend device of DVB adapter " << devFrontend << ".";
fd(f);
}
const
{
if (::ioctl(fd(), FE_READ_SIGNAL_STRENGTH, strength) < 0)
- throw SystemException( "Could not get signal strength of DVB adapter.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not get signal strength of DVB adapter.");
}
///////////////////////////////cc.e////////////////////////////////////////
{
struct timeval tv;
if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return tv;
}
unsigned len)
{
if (::getsockname(handle.fd(),addr,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::GenericAddressingPolicy_Base::do_peer(FileHandle handle,
unsigned len)
{
if (::getpeername(handle.fd(),addr,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::GenericAddressingPolicy_Base::do_bind(FileHandle handle,
unsigned len)
{
if (::bind(handle.fd(),addr,len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::GenericAddressingPolicy_Base::do_connect(FileHandle handle,
int err = 0;
socklen_t len = sizeof(err);
if (::getsockopt(handle.fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
if (err != 0)
- throw SystemException(err);
+ throw SystemException(err SENF_EXC_DEBUGINFO);
return;
}
case EINTR:
break;
default:
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
else
return;
{
int sock = ::socket(PF_INET, SOCK_RAW, protocol);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int sock = ::socket(PF_INET,SOCK_DGRAM,0);
if (sock < 0)
- throw SystemException("::socket(PF_INET,SOCK_DGRAM,0) failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("::socket(PF_INET,SOCK_DGRAM,0) failed.");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
if (sock < 0)
- throw SystemException("::socket(PF_INET6,SOCK_DGRAM,0) failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("::socket(PF_INET6,SOCK_DGRAM,0) failed.");
fd(sock);
}
const
{
if (::setsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) < 0)
- throw SystemException("::setsockopt(SO_BINDTODEVICE)");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(SO_BINDTODEVICE)");
}
prefix_ std::string senf::INetSocketProtocol::bindInterface()
socklen_t size (sizeof(iface));
::memset(iface, 0, sizeof(iface));
if (::getsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface, &size) < 0)
- throw SystemException("::getsockopt(SO_BINDTODEVICE)");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_BINDTODEVICE)");
iface[size < IFNAMSIZ ? size : IFNAMSIZ-1] = 0;
return iface;
}
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h> // for if_nametoindex
+#include "../../../Utils/Exception.hh"
//#include "MulticastSocketProtocol.mpp"
#define prefix_
{
int ivalue (v);
if (::setsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &ivalue, sizeof(ivalue)) < 0)
- throw SystemException("::setsockopt(SO_BROADCAST)");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(SO_BROADCAST)");
}
prefix_ bool senf::MulticastSocketProtocol::broadcastEnabled()
int value (0);
::socklen_t len (sizeof(value));
if (::getsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &value, &len) < 0)
- throw SystemException("::getsockopt(SO_BROADCAST)");
+ SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_BROADCAST)");
return value;
}
int value (0);
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface)
if (!iface.empty()) {
mreqn.imr_ifindex = if_nametoindex(iface.c_str());
if (mreqn.imr_ifindex == 0)
- throw SystemException(EINVAL);
+ throw SystemException(EINVAL SENF_EXC_DEBUGINFO);
}
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ unsigned senf::MulticastSocketProtocol::mcTTL()
int value (0);
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return value;
}
const
{
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
///////////////////////////////////////////////////////////////////////////
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP)");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_ADD_MEMBERSHIP)");
}
prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address const & mcAddr,
mreqn.imr_address.s_addr = localAddr.inaddr();
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_ADD_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address const & mcAddr,
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = if_nametoindex(iface.c_str());
if (mreqn.imr_ifindex == 0)
- throw SystemException("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_ADD_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr)
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
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)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr,
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = if_nametoindex(iface.c_str());
if (mreqn.imr_ifindex == 0)
- throw SystemException("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
///////////////////////////////////////////////////////////////////////////
std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
mreqn.ipv6mr_interface = 0;
if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException("::setsockopt(IPV6_ADD_MEMBERSHIP");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_ADD_MEMBERSHIP");
}
prefix_ void senf::INet6MulticastSocketProtocol::mcAddMembership(INet6Address const & mcAddr,
std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
mreqn.ipv6mr_interface = if_nametoindex(iface.c_str());
if (mreqn.ipv6mr_interface == 0)
- throw SystemException("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException("::setsockopt(IPV6_ADD_MEMBERSHIP");
+ SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_ADD_MEMBERSHIP");
}
prefix_ void senf::INet6MulticastSocketProtocol::mcDropMembership(INet6Address const & mcAddr)
std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
mreqn.ipv6mr_interface = 0;
if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ void
std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
mreqn.ipv6mr_interface = if_nametoindex(iface.c_str());
if (mreqn.ipv6mr_interface == 0)
- throw SystemException("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
///////////////////////////////cc.e////////////////////////////////////////
{
int sock = ::socket(PF_INET, SOCK_RAW, protocol);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return n;
}
{
int sock = ::socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int sock = ::socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
///////////////////////////////////////////////////////////////////////////
{
int sock = ::socket(PF_INET6,SOCK_STREAM,0);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_STREAM,0);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
///////////////////////////////cc.e////////////////////////////////////////
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
prefix_ unsigned senf::TCPSocketProtocol::siocinq()
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return n;
}
{
int n;
if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return n;
}
{
int sock = ::socket(PF_INET,SOCK_DGRAM,0);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
if (sock < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
fd(sock);
}
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return n;
}
protocol = ETH_P_ALL;
int sock = ::socket(PF_PACKET, socktype, htons(protocol));
if (sock < 0)
- throw SystemException("::socket(...) failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("::socket(...) failed.");
fd(sock);
}
return 0;
ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC);
if (l < 0)
- throw SystemException("::recv(socket_fd) failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("::recv(socket_fd) failed.");
return l;
}
{
int f;
if ( (f = ::open("/dev/net/tun", O_RDWR)) < 0 )
- throw SystemException( "Could not open tap control device: /dev/net/tun.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open tap control device: /dev/net/tun.");
struct ifreq ifr;
::memset( &ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP;
ifr.ifr_flags |= IFF_NO_PI;
interface_name.copy( ifr.ifr_name, IFNAMSIZ);
if (::ioctl(f, TUNSETIFF, (void *) &ifr) < 0 )
- throw SystemException( "Could not create tap device: ") << ifr.ifr_name << ".";
+ SENF_THROW_SYSTEM_EXCEPTION( "Could not create tap device: ") << ifr.ifr_name << ".";
fd(f);
}
return 0;
ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC);
if (l < 0)
- //throw SystemException();
+ //SENF_THROW_SYSTEM_EXCEPTION("");
return 1588;
return l;
}
return 0;
int n;
if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
return n;
}
*/
{
int sock = ::socket(PF_UNIX, SOCK_DGRAM, 0);
if (sock < 0)
- throw SystemException( "Could not create socket(PF_UNIX,SOCK_DGRAM,0)." );
+ SENF_THROW_SYSTEM_EXCEPTION("Could not create socket(PF_UNIX,SOCK_DGRAM,0).");
fd(sock);
}
{
int sock = ::socket(PF_UNIX,SOCK_DGRAM,0);
if (sock < 0)
- throw SystemException( "Could not create socket(PF_UNIX,SOCK_DGRAM,0)." );
+ SENF_THROW_SYSTEM_EXCEPTION("Could not create socket(PF_UNIX,SOCK_DGRAM,0).");
fd(sock);
}
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throw SystemException("Could not call available() on UNSocket.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not call available() on UNSocket.");
return n;
}
rv = 0;
break;
default:
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- throw SystemException();
+ SENF_THROW_SYSTEM_EXCEPTION("");
}
} while (rv<0);
return rv;
const
{
if (::shutdown(body().fd(),SHUT_RDWR) < 0)
- throw SystemException("::shutdown(socket_fd)");
+ SENF_THROW_SYSTEM_EXCEPTION("::shutdown(socket_fd)");
if (::close(body().fd()) < 0)
- throw SystemException("::close(socket_fd)");
+ SENF_THROW_SYSTEM_EXCEPTION("::close(socket_fd)");
}
prefix_ void senf::SocketProtocol::terminate()
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-#define LIBC_CALL(fn, args) if (fn args < 0) throw SystemException(#fn "()")
-#define LIBC_CALL_RV(var, fn, args) int var (fn args); if (var < 0) throw SystemException(#fn "()")
+#define LIBC_CALL(fn, args) if (fn args < 0) \
+ SENF_THROW_SYSTEM_EXCEPTION(#fn "()")
+
+#define LIBC_CALL_RV(var, fn, args) \
+ int var (fn args); if (var < 0) SENF_THROW_SYSTEM_EXCEPTION(#fn "()")
///////////////////////////////////////////////////////////////////////////
// senf::Daemon
if (! stdoutLog_.empty()) {
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0)
- throw SystemException()
+ SENF_THROW_SYSTEM_EXCEPTION("")
<< " Could not open \"" << stdoutLog_ << "\" for redirecting stdout.";
stdout_ = fd;
}
else if (! stderrLog_.empty()) {
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0)
- throw SystemException()
+ SENF_THROW_SYSTEM_EXCEPTION("")
<< " Could not open \"" << stderrLog_ << "\" for redirecting stderr.";
stderr_ = fd;
}
while (! signaled) {
::sigsuspend(&waitsig);
if (errno != EINTR)
- throw SystemException("::sigsuspend()");
+ SENF_THROW_SYSTEM_EXCEPTION("::sigsuspend()");
}
LIBC_CALL( ::sigaction, (SIGUSR1, &oldact, 0) );
{
std::ofstream pidf (tempname.c_str());
if (! pidf)
- throw SystemException()
+ SENF_THROW_SYSTEM_EXCEPTION("")
<< " Could not open pidfile \"" << tempname << "\" for output.";
pidf << ::getpid() << std::endl;
if (! pidf)
- throw SystemException()
+ SENF_THROW_SYSTEM_EXCEPTION("")
<< " Could not write to pidfile \"" << tempname << "\".";
}
if (::link(tempname.c_str(), pidfile_.c_str()) < 0) {
if (errno != EEXIST)
- throw SystemException() << linkErrorFormat % pidfile_ % tempname;
+ SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % pidfile_ % tempname;
}
else {
struct ::stat s;
LIBC_CALL( ::unlink, (tempname.c_str() ));
if (::link(pidfile_.c_str(), tempname.c_str()) < 0) {
if (errno != ENOENT)
- throw SystemException() << linkErrorFormat % tempname % pidfile_;
+ SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % tempname % pidfile_;
// Hmm ... the pidfile mysteriously disappeared ... try again.
continue;
}
if (sigChld_)
childDied(); // does not return
if (::kill(childPid_, SIGUSR1) < 0)
- if (errno != ESRCH) throw SystemException("::kill()");
+ if (errno != ESRCH) SENF_THROW_SYSTEM_EXCEPTION("::kill()");
Scheduler::instance().timeout(
Scheduler::instance().eventTime() + ClockService::seconds(1),
senf::membind(&DaemonWatcher::childOk, this));
prefix_ void senf::detail::DaemonWatcher::childDied()
{
int status (0);
- if (::waitpid(childPid_,&status,0) < 0) throw SystemException("::waitpid()");
+ if (::waitpid(childPid_,&status,0) < 0) SENF_THROW_SYSTEM_EXCEPTION("::waitpid()");
if (WIFSIGNALED(status)) {
::signal(WTERMSIG(status),SIG_DFL);
::kill(::getpid(), WTERMSIG(status));
while (1) {
n = ::read(src_,buf,1024);
if (n<0) {
- if (errno != EINTR) throw SystemException("::read()");
+ if (errno != EINTR) SENF_THROW_SYSTEM_EXCEPTION("::read()");
} else
break;
}
int w (::write(target->fd, buf, n));
if (w < 0) {
- if (errno != EINTR) throw SystemException("::write()");
+ if (errno != EINTR) SENF_THROW_SYSTEM_EXCEPTION("::write()");
return;
}
target->offset += w;
///////////////////////////////////////////////////////////////////////////
// senf::SystemException
-prefix_ void senf::SystemException::init(std::string const & descr, int code)
+prefix_ void senf::SystemException::init(std::string const & descr, int code
+ _SENF_EXC_DEBUG_ARGS_ND)
{
code_ = code;
+# ifdef SENF_DEBUG
+ if (file && line)
+ (*this) << "Exception at " << file << ":" << line << "\n";
+# endif
(*this) << "[" << errorString() << "]";
if (! descr.empty()) (*this) << " " << descr;
}
///////////////////////////////////////////////////////////////////////////
-prefix_ senf::SystemException::SystemException(std::string const & descr)
+prefix_ senf::SystemException::SystemException(std::string const & descr _SENF_EXC_DEBUG_ARGS_ND)
{
- init(descr, errno);
+ init(descr, errno _SENF_EXC_DEBUG_ARGS_P);
}
-prefix_ senf::SystemException::SystemException(int code)
+prefix_ senf::SystemException::SystemException(int code _SENF_EXC_DEBUG_ARGS_ND)
{
- init("", code);
+ init("", code _SENF_EXC_DEBUG_ARGS_P);
}
-prefix_ senf::SystemException::SystemException(std::string const & descr, int code)
+prefix_ senf::SystemException::SystemException(std::string const & descr, int code
+ _SENF_EXC_DEBUG_ARGS_ND)
{
- init(descr, code);
+ init(descr, code _SENF_EXC_DEBUG_ARGS_P);
}
prefix_ int senf::SystemException::errorNumber()
std::string message_;
};
+# ifdef SENF_DEBUG
+# define _SENF_EXC_DEBUG_ARGS ,char const * file=0,int line=0
+# define _SENF_EXC_DEBUG_ARGS_ND ,char const *file,int line
+# define _SENF_EXC_DEBUG_ARGS_P ,file,line
+# else
+# define _SENF_EXC_DEBUG_ARGS
+# define _SENF_EXC_DEBUG_ARGS_ND
+# define _SENF_EXC_DEBUG_ARGS_P
+# endif
/** \brief Exception handling standard UNIX errors (errno)
throw senf::SystemException();
\endcode
+ From within SENF (<em>and only there because it depends on the \c SENF_DEBUG symbol</em>),
+ SystemException should be thrown using wrapper macros which add additional information to
+ the exception description:
+ \code
+ // Standard usage: Take \c errno from environment
+ SENF_THROW_SYSTEM_EXCEPTION()
+ << " while opening configuration file: " << filename;
+
+ // You may however explicitly specify the errno value
+ throw senf::SystemException("::open()", ENOFILE SENF_EXC_DEBUGINFO)
+ \endcode
+
\ingroup exception
*/
class SystemException : public Exception
///\name Structors and default members
///@{
- explicit SystemException(std::string const & descr = "");
- explicit SystemException(int code);
- SystemException(std::string const & descr, int code);
+ explicit SystemException(std::string const & descr = "" _SENF_EXC_DEBUG_ARGS);
+ explicit SystemException(int code _SENF_EXC_DEBUG_ARGS);
+ SystemException(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS);
virtual ~SystemException() throw();
private:
- void init(std::string const & descr, int code);
+ void init(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS_ND);
int code_;
std::string what_;
};
+# ifdef SENF_DEBUG
+# define SENF_EXC_DEBUGINFO ,__FILE__,__LINE__
+# else
+# define SENF_EXC_DEBUGINFO
+# endif
+
+# define SENF_THROW_SYSTEM_EXCEPTION(desc) throw SystemException(desc SENF_EXC_DEBUGINFO)
+
}
///////////////////////////////hh.e////////////////////////////////////////