};
-struct ULEdecException : public std::exception
+struct ULEdecException : public senf::Exception
{
- ULEdecException(char const * what) : what_(what) {};
- ULEdecException(std::string const what) : what_(what) {};
- virtual char const * what() const throw() { return what_.c_str(); }
- virtual ~ULEdecException() throw() {};
- std::string what_;
+ ULEdecException(std::string const & what)
+ : senf::Exception(what) {}
};
// Custom includes
#include "../Scheduler/Scheduler.hh"
#include "Events.hh"
+#include "../Utils/Exception.hh"
//#include "IOEvent.mpp"
///////////////////////////////hh.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
/** \brief Unhandled error condition */
- struct ErrorException : public std::exception
- { virtual char const * what() const throw()
- { return "senf::ppi::IOEvent::ErrorException"; } };
+ struct ErrorException : public senf::Exception
+ { ErrorException() : senf::Exception("senf::ppi::IOEvent::ErrorException"){} };
/** \brief Unhandled hangup condition */
- struct HangupException : public std::exception
- { virtual char const * what() const throw()
- { return "senf::ppi::IOEvent::HangupException"; } };
+ struct HangupException : public senf::Exception
+ { HangupException() : senf::Exception("senf::ppi::IOEvent::HangupException"){} };
protected:
\todo add usefull exceptions strings
*/
- struct UnsuportedTLVPacketException : public std::exception
- {
- virtual char const * what() const throw() {
- return "length of length can be max. 4 bytes. Sorry.";
- }
- };
+ struct UnsuportedTLVPacketException : public senf::Exception
+ { UnsuportedTLVPacketException()
+ : senf::Exception("length of length can be max. 4 bytes. Sorry."){} };
/** \brief xxx
\todo document me
#include <boost/type_traits.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include "../Utils/safe_bool.hh"
+#include "../Utils/Exception.hh"
#include "PacketTypes.hh"
//#include "PacketData.mpp"
This exception is signaled whenever an operation tries to access an out-of-bounds data
byte. If the packet has been implemented correctly, this signals a malformed packet.
*/
- struct TruncatedPacketException : public std::exception
- { virtual char const * what() const throw() { return "truncated packet"; } };
+ struct TruncatedPacketException : public senf::Exception
+ { TruncatedPacketException() : senf::Exception("truncated packet"){} };
/** \brief Re-validating data iterator
This exception signals an invalid operation on the chain like trying to find a non-existent
chain member and other similar error conditions.
*/
- struct InvalidPacketChainException : public std::exception
- { virtual char const * what() const throw() { return "invalid packet chain"; } };
+ struct InvalidPacketChainException : public senf::Exception
+ { InvalidPacketChainException() : senf::Exception("invalid packet chain"){} };
}
This exception is signaled whenever a throwing lookup operation fails.
*/
- struct PacketTypeNotRegisteredException : public std::exception
- { virtual char const * what() const throw() { return "packet type not registered"; } };
+ struct PacketTypeNotRegisteredException : public senf::Exception
+ { PacketTypeNotRegisteredException() : senf::Exception("packet type not registered"){} };
}
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-#define CheckError(op,args) if (op args < 0) throwErrno(# op, errno)
+#define CheckError(op,args) if (op args < 0) throw SystemException(# op, errno)
///////////////////////////////////////////////////////////////////////////
// senf::ClockService::Impl
{
try {
if (event != senf::Scheduler::EV_READ)
- throwErrno(EPIPE);
+ throw SystemException(EPIPE);
std::string rcv;
handle.read(rcv, maxSize_ - data_.size());
data_.append(rcv);
prefix_ void senf::ReadHelper<Handle>::throw_error()
const
{
- if (errno_ != 0) throwErrno(errno_);
+ if (errno_ != 0) throw SystemException(errno_);
}
///////////////////////////////cti.e///////////////////////////////////////
eventTime_(0), eventEarly_(ClockService::milliseconds(11)), eventAdjust_(0)
{
if (epollFd_<0)
- throwErrno();
+ throw SystemException();
if (::pipe(sigpipe_) < 0)
- throwErrno();
+ throw SystemException();
int flags (::fcntl(sigpipe_[1],F_GETFL));
if (flags < 0)
- throwErrno();
+ throw SystemException();
flags |= O_NONBLOCK;
if (::fcntl(sigpipe_[1], F_SETFL, flags) < 0)
- throwErrno();
+ throw SystemException();
::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)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::Scheduler::registerSignal(unsigned signal, SimpleCallback const & cb)
++ files_;
}
else
- throwErrno("::epoll_ctl()");
+ throw SystemException("::epoll_ctl()");
}
}
}
if (! file && epoll_ctl(epollFd_, action, fd, &ev) < 0)
- throwErrno("::epoll_ctl()");
+ throw SystemException("::epoll_ctl()");
if (file)
-- files_;
}
if (signal == SIGCHLD)
sa.sa_flags |= SA_NOCLDSTOP;
if (::sigaction(signal, &sa, 0) < 0)
- throwErrno();
+ throw SystemException();
}
}
}
if (events<0)
if (errno != EINTR)
- throwErrno();
+ throw SystemException();
eventTime_ = ClockService::now();
///< Remove signal handler for \a signal
/// The signal number passed to registerSignal or unregisterSignal is invalid
- struct InvalidSignalNumberException : public std::exception
- { virtual char const * what() const throw()
- { return "senf::Scheduler::InvalidSignalNumberException"; } };
+ struct InvalidSignalNumberException : public senf::Exception
+ { InvalidSignalNumberException()
+ : senf::Exception("senf::Scheduler::InvalidSignalNumberException"){} };
///\}
bool complete_ (false);
try {
if (event != senf::Scheduler::EV_WRITE)
- throwErrno(EPIPE);
+ throw SystemException(EPIPE);
offset_ = handle.write(std::make_pair(offset_,data_.end()));
if (offset_ == data_.end()) {
data_.erase();
const
{
if (errno_ != 0)
- throwErrno(errno_);
+ throw SystemException(errno_);
}
case EINTR:
break;
default:
- throwErrno();
+ throw SystemException();
}
} while (rv<0);
return rv;
prefix_ void senf::FileBody::close()
{
if (!valid())
- throwErrno(EBADF);
+ throw SystemException(EBADF);
v_close();
fd_ = -1;
}
prefix_ void senf::FileBody::v_close()
{
if (::close(fd_) != 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::FileBody::v_terminate()
const
{
int flags = ::fcntl(fd(),F_GETFL);
- if (flags < 0) throwErrno();
+ if (flags < 0) throw SystemException();
return ! (flags & O_NONBLOCK);
}
prefix_ void senf::FileBody::blocking(bool status)
{
int flags = ::fcntl(fd(),F_GETFL);
- if (flags < 0) throwErrno();
+ if (flags < 0) throw SystemException();
if (status) flags &= ~O_NONBLOCK;
else flags |= O_NONBLOCK;
- if (::fcntl(fd(), F_SETFL, flags) < 0) throwErrno();
+ if (::fcntl(fd(), F_SETFL, flags) < 0) throw SystemException();
}
/* We don't take POLLIN/POLLOUT as argument to avoid having to include
case EINTR:
break;
default:
- throwErrno();
+ throw SystemException();
}
} while (rv<0);
return rv>0;
{
int rv = ::open(name.c_str(),O_RDWR|O_NONBLOCK) ;
if (rv<0)
- senf::throwErrno();
+ throw senf::SystemException();
fd(rv);
}
};
{
sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0);
if ( sockfd_ < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr)
::memset( &ifr, 0, sizeof(ifr));
ifr.ifr_ifindex = ifindex_;
if ( ::ioctl( sockfd_, SIOCGIFNAME, &ifr ) < 0 )
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::NetdeviceController::doIoctl(ifreq& ifr, int request)
{
if ( ::ioctl( sockfd_, request, &ifr ) < 0 )
- throwErrno();
+ throw SystemException();
}
///////////////////////////////cc.e////////////////////////////////////////
#define HH_AddressExceptions_ 1
// Custom includes
+#include "../Utils/Exception.hh"
//#include "AddressExceptions.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
/** \brief Base-class for INet4Address exceptions */
- struct AddressException : public std::exception {};
+ struct AddressException : public senf::Exception
+ {
+ protected:
+ AddressException(std::string const & msg)
+ : senf::Exception(msg) {}
+ };
/** \brief Invalid INet4 address syntax */
struct AddressSyntaxException : public AddressException
- { virtual char const * what() const throw()
- { return "invalid INet4 address syntax"; } };
+ { AddressSyntaxException() : AddressException("invalid INet4 address syntax") {} };
/** \brief Resolver failure */
struct UnknownHostnameException : public AddressException
- { virtual char const * what() const throw()
- { return "failed to resolve INet4 hostname"; } };
+ { UnknownHostnameException() : AddressException("failed to resolve INet4 hostname") {} };
}
socklen_t len = sizeof(ling);
::memset(&ling,sizeof(ling),0);
if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
- throwErrno();
+ throw SystemException();
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)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////////////////////////////////////////////////
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
- throwErrno();
+ throw SystemException();
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ boost::uint8_t senf::AddressableBSDSocketProtocol::priority()
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
- throwErrno();
+ throw SystemException();
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ unsigned senf::AddressableBSDSocketProtocol::rcvbuf()
unsigned size;
socklen_t len (sizeof(size));
if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
- throwErrno();
+ throw SystemException();
// 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)
- throwErrno();
+ throw SystemException();
}
prefix_ unsigned senf::AddressableBSDSocketProtocol::sndbuf()
unsigned size;
socklen_t len (sizeof(size));
if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
- throwErrno();
+ throw SystemException();
// 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)
- throwErrno();
+ throw SystemException();
}
/////////////////////////////cc.e////////////////////////////////////////
"/dev/dvb/adapter%d/demux%d") % adapter % device);
int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throwErrno();
+ throw SystemException();
fd(f);
}
const
{
if (::ioctl(fd(), DMX_SET_FILTER, filter) < 0)
- throwErrno();
+ throw SystemException();
}
// ----------------------------------------------------------------
"/dev/dvb/adapter%d/demux%d") % adapter % device);
int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throwErrno();
+ throw SystemException();
fd(f);
}
const
{
if (::ioctl(fd(), DMX_SET_PES_FILTER, filter) < 0)
- throwErrno();
+ throw SystemException();
}
// ----------------------------------------------------------------
"/dev/dvb/adapter%d/dvr%d") % adapter % device);
int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throwErrno();
+ throw SystemException();
fd(f);
}
const
{
if (::ioctl(fd(), DMX_SET_BUFFER_SIZE, size) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::DVBDemuxProtocol::startFiltering()
const
{
if (::ioctl(fd(), DMX_START) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::DVBDemuxProtocol::stopFiltering()
const
{
if (::ioctl(fd(), DMX_STOP) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ bool senf::DVBDemuxProtocol::eof()
"/dev/dvb/adapter%d/frontend%d") % adapter % device);
int f = open(devFrontend.c_str(), O_RDONLY | O_NONBLOCK);
if (f < 0)
- throwErrno();
+ throw SystemException();
fd(f);
}
const
{
if (::ioctl(fd(), FE_READ_SIGNAL_STRENGTH, strength) < 0)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////cc.e////////////////////////////////////////
{
struct timeval tv;
if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
- throwErrno();
+ throw SystemException();
return tv;
}
unsigned len)
{
if (::getsockname(handle.fd(),addr,&len) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::GenericAddressingPolicy_Base::do_peer(FileHandle handle,
unsigned len)
{
if (::getpeername(handle.fd(),addr,&len) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::GenericAddressingPolicy_Base::do_bind(FileHandle handle,
unsigned len)
{
if (::bind(handle.fd(),addr,len) < 0)
- throwErrno();
+ throw SystemException();
}
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)
- throwErrno();
+ throw SystemException();
if (err != 0)
- throwErrno(err);
+ throw SystemException(err);
return;
}
case EINTR:
break;
default:
- throwErrno();
+ throw SystemException();
}
else
return;
{
int sock = ::socket(PF_INET, SOCK_RAW, protocol);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET,SOCK_DGRAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
const
{
if (::setsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) < 0)
- throwErrno("::setsockopt(SO_BINDTODEVICE)");
+ throw SystemException("::setsockopt(SO_BINDTODEVICE)");
}
prefix_ std::string senf::INetProtocol::bindInterface()
socklen_t size (sizeof(iface));
::memset(iface, 0, sizeof(iface));
if (::getsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface, &size) < 0)
- throwErrno("::getsockopt(SO_BINDTODEVICE)");
+ throw SystemException("::getsockopt(SO_BINDTODEVICE)");
iface[size < IFNAMSIZ ? size : IFNAMSIZ-1] = 0;
return iface;
}
{
int ivalue (v);
if (::setsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &ivalue, sizeof(ivalue)) < 0)
- throwErrno("::setsockopt(SO_BROADCAST)");
+ throw SystemException("::setsockopt(SO_BROADCAST)");
}
prefix_ bool senf::MulticastProtocol::broadcastEnabled()
int value (0);
::socklen_t len (sizeof(value));
if (::getsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &value, &len) < 0)
- throwErrno("::getsockopt(SO_BROADCAST)");
+ throw SystemException("::getsockopt(SO_BROADCAST)");
return value;
}
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
- throwErrno();
+ throw SystemException();
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::MulticastProtocol::mcIface(std::string const & iface)
if (!iface.empty()) {
mreqn.imr_ifindex = if_nametoindex(iface.c_str());
if (mreqn.imr_ifindex == 0)
- throwErrno(EINVAL);
+ throw SystemException(EINVAL);
}
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ unsigned senf::MulticastProtocol::mcTTL()
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
- throwErrno();
+ throw SystemException();
return value;
}
const
{
if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////////////////////////////////////////////////
mreqn.imr_address.s_addr = htons(INADDR_ANY);
mreqn.imr_ifindex = 0;
if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno("::setsockopt(IP_ADD_MEMBERSHIP");
+ throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastProtocol::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)
- throwErrno("::setsockopt(IP_ADD_MEMBERSHIP");
+ throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastProtocol::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)
- throwErrno("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT);
if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno("::setsockopt(IP_ADD_MEMBERSHIP");
+ throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP");
}
prefix_ void senf::INet4MulticastProtocol::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)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::INet4MulticastProtocol::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)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::INet4MulticastProtocol::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)
- throwErrno("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT);
if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////////////////////////////////////////////////
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)
- throwErrno("::setsockopt(IPV6_ADD_MEMBERSHIP");
+ throw SystemException("::setsockopt(IPV6_ADD_MEMBERSHIP");
}
prefix_ void senf::INet6MulticastProtocol::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)
- throwErrno("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT);
if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno("::setsockopt(IPV6_ADD_MEMBERSHIP");
+ throw SystemException("::setsockopt(IPV6_ADD_MEMBERSHIP");
}
prefix_ void senf::INet6MulticastProtocol::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)
- throwErrno();
+ throw SystemException();
}
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)
- throwErrno("::if_nametoindex()",ENOENT);
+ throw SystemException("::if_nametoindex()",ENOENT);
if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////cc.e////////////////////////////////////////
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throwErrno();
+ throw SystemException();
return n;
}
{
int sock = ::socket(PF_INET, SOCK_RAW, protocol);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
int value;
socklen_t len (sizeof(value));
if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
- throwErrno();
+ throw SystemException();
return value;
}
{
int ivalue (value);
if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ unsigned senf::TCPProtocol::siocinq()
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throwErrno();
+ throw SystemException();
return n;
}
{
int n;
if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
- throwErrno();
+ throw SystemException();
return n;
}
{
int sock = ::socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////////////////////////////////////////////////
{
int sock = ::socket(PF_INET6,SOCK_STREAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_STREAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
- throwErrno();
+ throw SystemException();
}
///////////////////////////////cc.e////////////////////////////////////////
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throwErrno();
+ throw SystemException();
return n;
}
{
int sock = ::socket(PF_INET,SOCK_DGRAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
protocol = ETH_P_ALL;
int sock = ::socket(PF_PACKET, socktype, htons(protocol));
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
return 0;
ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC);
if (l < 0)
- throwErrno();
+ throw SystemException();
return l;
}
struct packet_mreq mreq;
mreq.mr_ifindex = ::if_nametoindex(interface.c_str());
if (mreq.mr_ifindex == 0)
- senf::throwErrno(EINVAL);
+ throw senf::SystemException(EINVAL);
mreq.mr_type = PACKET_MR_MULTICAST;
mreq.mr_alen = 6;
std::copy(address.begin(), address.end(), &mreq.mr_address[0]);
if (::setsockopt(fd, SOL_PACKET,
add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0)
- senf::throwErrno();
+ throw senf::SystemException();
}
}
{
int f;
if ( (f = ::open("/dev/net/tun", O_RDWR)) < 0 )
- throwErrno();
+ throw SystemException();
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 )
- throwErrno();
+ throw SystemException();
fd(f);
}
return 0;
ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC);
if (l < 0)
- //throwErrno();
+ //throw SystemException();
return 1588;
return l;
}
return 0;
int n;
if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
- throwErrno();
+ throw SystemException();
return n;
}
*/
{
int sock = ::socket(PF_UNIX,SOCK_DGRAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int sock = ::socket(PF_UNIX,SOCK_DGRAM,0);
if (sock < 0)
- throwErrno();
+ throw SystemException();
fd(sock);
}
{
int n;
if (::ioctl(fd(),SIOCINQ,&n) < 0)
- throwErrno();
+ throw SystemException();
return n;
}
rv = 0;
break;
default:
- throwErrno();
+ throw SystemException();
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- throwErrno();
+ throw SystemException();
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- throwErrno();
+ throw SystemException();
}
} while (rv<0);
return rv;
rv = 0;
break;
default:
- throwErrno();
+ throw SystemException();
}
} while (rv<0);
return rv;
const
{
if (::shutdown(body().fd(),SHUT_RDWR) < 0)
- throwErrno();
+ throw SystemException();
if (::close(body().fd()) < 0)
- throwErrno();
+ throw SystemException();
}
prefix_ void senf::SocketProtocol::terminate()
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-#define LIBC_CALL(fn, args) if (fn args < 0) throwErrno(#fn "()")
-#define LIBC_CALL_RV(var, fn, args) int var (fn args); if (var < 0) throwErrno(#fn "()")
+#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 "()")
///////////////////////////////////////////////////////////////////////////
// senf::Daemon
if (! stdoutLog_.empty()) {
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0)
- throwErrno("::open()");
+ throw SystemException("::open()");
stdout_ = fd;
}
if (stderrLog_ == stdoutLog_)
else if (! stderrLog_.empty()) {
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0)
- throwErrno("::open()");
+ throw SystemException("::open()");
stderr_ = fd;
}
}
while (! signaled) {
::sigsuspend(&waitsig);
if (errno != EINTR)
- throwErrno("::sigsuspend()");
+ throw SystemException("::sigsuspend()");
}
LIBC_CALL( ::sigaction, (SIGUSR1, &oldact, 0) );
if (::link(tempname.c_str(), pidfile_.c_str()) < 0) {
if (errno != EEXIST)
- throwErrno("::link()");
+ throw SystemException("::link()");
}
else {
struct ::stat s;
LIBC_CALL( ::unlink, (tempname.c_str() ));
if (::link(pidfile_.c_str(), tempname.c_str()) < 0) {
- if (errno != ENOENT) throwErrno("::link()");
+ if (errno != ENOENT) throw SystemException("::link()");
// Hmm ... the pidfile mysteriously disappeared ... try again.
continue;
}
if (sigChld_)
childDied(); // does not return
if (::kill(childPid_, SIGUSR1) < 0)
- if (errno != ESRCH) throwErrno("::kill()");
+ if (errno != ESRCH) throw SystemException("::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) throwErrno("::waitpid()");
+ if (::waitpid(childPid_,&status,0) < 0) throw SystemException("::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) throwErrno("::read()");
+ if (errno != EINTR) throw SystemException("::read()");
} else
break;
}
int w (::write(target->fd, buf, n));
if (w < 0) {
- if (errno != EINTR) throwErrno("::write()");
+ if (errno != EINTR) throw SystemException("::write()");
return;
}
target->offset += w;
int run(int argc, char const ** argv)
{
int pid (::fork());
- if (pid < 0) senf::throwErrno("::fork()");
+ if (pid < 0) throw senf::SystemException("::fork()");
if (pid == 0) {
::_exit(myMain(argc, argv));
}
int status;
- if (::waitpid(pid, &status, 0) < 0) senf::throwErrno("::waitpid()");
+ if (::waitpid(pid, &status, 0) < 0) throw senf::SystemException("::waitpid()");
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
}
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-prefix_ void senf::throwErrno(std::string const & where, int code)
-{
-#ifndef SENF_NO_ERRNOEXC
- switch (code) {
-
- // BOOST_PP_REPEAT is limited to 256 repetitions. The max errno value I found in any header file
- // was somewhere around 530 or so. I assume going to 1024 will be good enough. This explicit
- // code will be optimized into a jump table by g++ (which is more efficient than trying to do
- // the table oneself)
-
-# define ExceptionCase(z, n, data) case n: throw ErrnoException<n>(where);
- BOOST_PP_REPEAT(256, ExceptionCase, _) ;
-# undef ExceptionCase
+///////////////////////////////////////////////////////////////////////////
+// senf::Exception
-# define ExceptionCase(z, n, data) case 256+n: throw ErrnoException<256+n>(where);
- BOOST_PP_REPEAT(256, ExceptionCase, _) ;
-# undef ExceptionCase
+prefix_ senf::Exception::~Exception()
+ throw()
+{}
-# define ExceptionCase(z, n, data) case 512+n: throw ErrnoException<512+n>(where);
- BOOST_PP_REPEAT(256, ExceptionCase, _) ;
-# undef ExceptionCase
-
-# define ExceptionCase(z, n, data) case 768+n: throw ErrnoException<768+n>(where);
- BOOST_PP_REPEAT(256, ExceptionCase, _) ;
-# undef ExceptionCase
-
- default:
- throw SystemException(where, code);
- }
-#else
- throw SystemException(where, code);
-#endif
+prefix_ char const * senf::Exception::what()
+ const throw()
+{
+ return message_.c_str();
}
///////////////////////////////cc.e////////////////////////////////////////
#define prefix_ inline
///////////////////////////////cci.p///////////////////////////////////////
-prefix_ senf::SystemException::SystemException(SystemException const & other)
- : std::stringstream(other.str(),std::ios::out), code_(other.code_)
+///////////////////////////////////////////////////////////////////////////
+// senf::Exception
+prefix_ senf::Exception::Exception(std::string const & description)
+ : message_(description)
{}
-prefix_ senf::SystemException::SystemException(std::string const & where, int code)
- : std::stringstream(std::ios::out), code_(code)
+///////////////////////////////////////////////////////////////////////////
+
+prefix_ senf::SystemException::SystemException(std::string const & where)
{
- if (! where.empty())
- (*this) << where << ": ";
- (*this) << "(" << code_ << ") " << description();
+ init(where, errno);
}
-prefix_ char const * senf::SystemException::what()
- const throw()
+prefix_ senf::SystemException::SystemException(int code)
+{
+ init("", code);
+}
+
+prefix_ senf::SystemException::SystemException(std::string const & where, int code)
{
- /// \fixme Replace the 'stringstream' base-class with our own stream with a specialized
- /// streambuf which allows to efficiently access the contents as a C string.
- buffer_ = this->str();
- return buffer_.c_str();
+ init(where, code);
}
prefix_ int senf::SystemException::errorNumber()
throw()
{}
-prefix_ void senf::throwErrno()
+prefix_ void senf::SystemException::init(std::string const & where, int code)
{
- throwErrno("", errno);
-}
-
-prefix_ void senf::throwErrno(std::string const & where)
-{
- throwErrno(where, errno);
-}
-
-prefix_ void senf::throwErrno(int code)
-{
- throwErrno("", code);
+ code_ = code;
+ if (! where.empty())
+ (*this) << where << ": ";
+ (*this) << "(" << code << ") " << description();
}
///////////////////////////////cci.e///////////////////////////////////////
//#include "Exception.ih"
// Custom includes
+#include <boost/lexical_cast.hpp>
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
-template <int Code>
-prefix_ senf::ErrnoException<Code>::ErrnoException(std::string const & where)
- : SystemException(where,fixed_code)
-{}
-
-// I for some reason need to explicitly define this constructor even though it's defined identically
-// to the default version (even though SyntaxException has a custom copy constructor, the
-// non-existent std::stringstream copy constructor will be called otherwise). I believe this is a
-// g++ bug.
-template <int Code>
-prefix_ senf::ErrnoException<Code>::ErrnoException(ErrnoException const & other)
- : SystemException(other)
-{}
+template <class Arg>
+prefix_ senf::Exception & senf::Exception::operator<<(Arg const & arg)
+{
+ message_ += boost::lexical_cast<std::string>(arg);
+ return *this;
+}
/////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
//#include "Exception.mpp"
///////////////////////////////hh.p////////////////////////////////////////
-/** \defgroup exception System exceptions
+/** \defgroup exception Exception classes
- The senf::SystemException class and it's derived class template senf::ErrnoException are used to
- signal generic system failures based on \c errno codes.
-
- senf::SystemException is a generic \c errno based exception which carries an error number and
- origin information. senf::ErrnoException is a derived class specialized for a specific error
- code. This simplifies managing error conditions:
+ All exceptions in senf are derived from senf::Exception. This class adds the possibility to
+ extend the exception description while it is processed:
\code
try {
- something.open(path);
- // ...
- }
- catch (senf::ErrnoException<ENOFILE> & e) {
- // Create new file
+
+ // Some code which might raise an arbitrary senf exception
+
}
- catch (senf::SystemException & e) {
- // Catch all other system exceptions
- std::cerr << "Error accessing '" << path << "': " << e.what() << std::endl;
+ catch (senf::Exception & e) {
+ e << "\handling user " << user;
+ throw;
}
\endcode
- This exception is normally thrown using the senf::throwErrno() helper:
+ This will add the user information to any senf exception thrown. The Exception is however not a
+ stream. If you need to do more extensive formating, either use an intermediate string-stream or
+ use <a href="http://www.boost.org/libs/format/doc/format.html">Boost.Format</a>:
\code
- if ((fd = ::open(path.c_str(), O_RDWR)) < 0)
- senf::throwErrno("::open()");
+ try {
+ // ...
+ }
+ catch (senf::Exception & e) {
+ e << boost::format("\ncall id 0x%04x@%s") % id % address;
+ }
\endcode
- The senf::throwErrno() helper will throw the correct exception class based on some \c errno
- value.
- */
+ senf::SystemException is thrown for all operating system errors (failures which result in the
+ operating system setting the errno value). It is also derived from senf::Exception and can
+ therefore be extended as well.
-namespace senf {
+ Defining your own exception classes derived from senf::Exception is very simple:
- /** \brief Exception handling standard UNIX errors (errno)
+ \code
+ struct FooException : public senf::Exception
+ { FooException() : senf::Exception("Foo hit the fan") {} };
+ \endcode
+ */
- This exception is thrown to signal generic \c errno failures.
+namespace senf {
- This exception cannot be thrown directly. Instead the derived class ErrnoException should be
- thrown via one of the senf::throwErrno helpers.
+ /** \brief Generic exception base-class
- The error message associated with the SystemException may be extended arbitrarily by using
- the exception like a stream:
- \code
- try {
- // This throw would normally be within some function called from here.
- senf::throwErrno("::open()");
-
- // Or you may want to use a more descriptive argument string:
- senf::throwErrno("::open(\"" + filename + "\")");
-
- // Or even use boost::format here
- senf::throwErrno((boost::format("::open(\"%s\")") % filename).str());
- }
- catch (SystemException & e) {
- // You can add further error information later by catching and re-throwing the exception
- e << " [while operating on user '" << user << "']";
- throw;
- }
- \endcode
+ Exception is a generic exception base-class which allows the exception to be later extended
+ by catching and re-throwing it (See example in \ref exception).
- \see ErrnoException
\ingroup exception
- */
- class SystemException : public std::exception, public std::stringstream
+ */
+ class Exception
+ : public std::exception
{
public:
- virtual char const * what() const throw(); ///< Return verbose error description
+ ///////////////////////////////////////////////////////////////////////////
+ ///\name Structors and default members
+ ///@{
- int errorNumber() const; ///< Error code (\c errno number)
- char const * description() const; ///< Error description (strerror() value)
+ virtual ~Exception() throw();
- bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0,
- int c6=0, int c7=0, int c8=0, int c9=0);
- ///< \c true, if errorNumber() is one of \a c0 ... \a c9
+ ///@}
+ ///////////////////////////////////////////////////////////////////////////
- virtual ~SystemException() throw();
+ virtual char const * what() const throw();
+
+ template <class Arg>
+ Exception & operator<<(Arg const & arg); ///< Extend exception description
+ /**< Adds \a arg converted to string to the end of the
+ exception description string. This operator allows to
+ use Exception instances like streams. The conversion is
+ performed using <code>boost::lexical_cast</code> and is
+ therefor identical to a streaming operation.
+ \see \ref exception */
protected:
- SystemException(std::string const & where, int code);
- SystemException(SystemException const & other);
+ Exception(std::string const & description = ""); ///< Initialize exception with string
+ /**< \a description is the initial error description
+ string. This should probably be a string constant
+ describing the exception for most derived
+ exceptions. */
private:
- int const code_; // This must be const to make the derived ErrnoException
- // class a valid derived class.
- mutable std::string buffer_;
-
- friend void throwErrno(std::string const &, int);
+ std::string message_;
};
- /** \brief Error specific system exception
- This template restricts the generic SystemException to a specific, compile-time constant
- error number \p Code. This allows a specific \c errno number to be cached explicitly.
+ /** \brief Exception handling standard UNIX errors (errno)
+
+ This exception is thrown to signal generic \c errno failures. Normally the \c errno value is
+ automatically taken from the \c errno variable but it may also be specified explicitly:
- This exception is normally thrown via one of the senf::throwErrno() helpers. These helpers
- take the numeric \c errno value (either from the \c errno variable or from their
- argument) and will throw the corresponding ErrnoException:
\code
- if ((fd = ::open(filename, O_RDWR)) < 0)
- senf::throwErrno("open()");
- \endcode
+ // Standard usage: Take \c errno from environment
+ throw senf::SystemException("::open()")
+ << " while opening configuration file: " << filename;
- \see SystemException
+ // You may however explicitly specify the errno value
+ throw senf::SystemException("::open()", ENOFILE)
+
+ // Or leave the location information empty
+ throw senf::SystemException(ENOFILE);
+ throw senf::SystemException();
+ \endcode
\ingroup exception
*/
- template <int Code>
- class ErrnoException : public SystemException
+ class SystemException : public Exception
{
public:
- static int const fixed_code = Code;
+ ///////////////////////////////////////////////////////////////////////////
+ ///\name Structors and default members
+ ///@{
- explicit ErrnoException(std::string const & where);
- ///< ErrnoException with error location information
-
- ErrnoException(ErrnoException const & other);
- };
+ explicit SystemException(std::string const & where = "");
+ explicit SystemException(int code);
+ SystemException(std::string const & where, int code);
-
- /** \brief Throw ErrnoException based on current \c errno value
- \ingroup exception
- */
- void throwErrno();
+ virtual ~SystemException() throw();
- /** \brief Throw ErrnoException based on current \c errno value (with location info)
- \ingroup exception
- */
- void throwErrno(std::string const & where);
+ ///@}
+ ///////////////////////////////////////////////////////////////////////////
- /** \brief Throw ErrnoException based on given \c errno value
- \ingroup exception
- */
- void throwErrno(int code);
+ int errorNumber() const; ///< Error code (\c errno number)
+ char const * description() const; ///< Error description (\c strerror() value)
- /** \brief Throw ErrnoException based on given \c errno value (with location info)
- \ingroup exception
- */
- void throwErrno(std::string const & where, int code);
+ bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0,
+ int c6=0, int c7=0, int c8=0, int c9=0);
+ ///< \c true, if errorNumber() is one of \a c0 ... \a c9
+
+
+
+ private:
+ void init(std::string const & where, int code);
+
+ int code_;
+ };
}
BOOST_AUTO_UNIT_TEST(errnoException)
{
- BOOST_CHECK_THROW( senf::throwErrno(), senf::SystemException );
- BOOST_CHECK_THROW( senf::throwErrno(ENOENT), senf::SystemException );
- BOOST_CHECK_THROW( senf::throwErrno(""), senf::SystemException );
- BOOST_CHECK_THROW( senf::throwErrno("", ENOENT), senf::SystemException );
-
try {
try {
- senf::throwErrno("::open()", ENOENT);
+ throw senf::SystemException("::open()", ENOENT);
}
- catch(senf::SystemException & e) {
- e << ": x=" << 1 << boost::format(", y=%d") % 2;
+ catch(senf::Exception & e) {
+ e << "\nx=" << 1 << boost::format("\ny=%d") % 2;
throw;
}
}
catch (senf::SystemException & e) {
BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT );
- BOOST_CHECK_EQUAL( e.what(), "::open(): (2) No such file or directory: x=1, y=2" );
+ BOOST_CHECK_EQUAL( e.what(), "::open(): (2) No such file or directory\nx=1\ny=2" );
}
}
#include "../mpl.hh"
#include "StreamRegistry.hh"
#include "AreaRegistry.hh"
+#include "../Exception.hh"
//#include "Target.mpp"
///////////////////////////////hh.p////////////////////////////////////////
///\}
/** \brief Exception: Invalid stream */
- struct InvalidStreamException : public std::exception
- { virtual char const * what() const throw()
- { return "senf::log::Target::InvalidStreamException"; } };
+ struct InvalidStreamException : public senf::Exception
+ { InvalidStreamException()
+ : senf::Exception("senf::log::Target::InvalidStreamException"){} };
/** \brief Exception: Invalid area */
- struct InvalidAreaException : public std::exception
- { virtual char const * what() const throw()
- { return "senf::log::Target::InvalidAreaException"; } };
+ struct InvalidAreaException : public senf::Exception
+ { InvalidAreaException()
+ : senf::Exception("senf::log::Target::InvalidAreaException"){} };
iterator begin() const; ///< Iterator to beginning of routing table
iterator end() const; ///< Iterator past the end of routing table
# -*- python -*-
Import('env')
-import SENFSCons, glob
+import SENFSCons, glob, os.path
###########################################################################
SENFSCons.StandardTargets(env)
# OUCH ... another hack to work around a scons bug ...
-Execute(Touch("Logger/all_includes.hh"))
+if not os.path.exists("Logger/all_includes.hh"):
+ Execute(Touch("Logger/all_includes.hh"))
sources, testSources = SENFSCons.GlobSources()
objects = SENFSCons.Objects( env, sources = sources, testSources=testSources )
if [ "$1" == "-c" ]; then
echo '$ find -mindepth 1 -maxdepth 1 ! -name .svn | xargs rm -rf'
- find -mindepth 1 -maxdepth 1 ! -name .svn ! -name build.log | xargs rm -rf
+ find -mindepth 1 -maxdepth 1 ! -name .svn | xargs rm -rf
fi
echo '$ svn update'