From: g0dil Date: Tue, 12 Feb 2008 00:06:32 +0000 (+0000) Subject: Utils: Removed ErrnoException and implemented generic Exception base-class X-Git-Url: http://g0dil.de/git?p=senf.git;a=commitdiff_plain;h=1d247d12d1759ffd77f456efe3a52f03dd289994 Utils: Removed ErrnoException and implemented generic Exception base-class Changed all exceptions to inherit from senf::Exception Replaced all throwErrno() calls with throw SystemException() git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@684 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Examples/DVBAdapter/ULEdec.hh b/Examples/DVBAdapter/ULEdec.hh index f73d424..60f757b 100644 --- a/Examples/DVBAdapter/ULEdec.hh +++ b/Examples/DVBAdapter/ULEdec.hh @@ -65,13 +65,10 @@ private: }; -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) {} }; diff --git a/PPI/IOEvent.hh b/PPI/IOEvent.hh index 5a3e188..d2f9528 100644 --- a/PPI/IOEvent.hh +++ b/PPI/IOEvent.hh @@ -29,6 +29,7 @@ // Custom includes #include "../Scheduler/Scheduler.hh" #include "Events.hh" +#include "../Utils/Exception.hh" //#include "IOEvent.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -94,14 +95,12 @@ namespace ppi { /////////////////////////////////////////////////////////////////////////// /** \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: diff --git a/Packets/MPEGDVBBundle/TLVPacket.hh b/Packets/MPEGDVBBundle/TLVPacket.hh index 729c419..4925075 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.hh +++ b/Packets/MPEGDVBBundle/TLVPacket.hh @@ -41,12 +41,9 @@ namespace senf { \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 diff --git a/Packets/PacketData.hh b/Packets/PacketData.hh index a2c1fa1..96db5b1 100644 --- a/Packets/PacketData.hh +++ b/Packets/PacketData.hh @@ -31,6 +31,7 @@ #include #include #include "../Utils/safe_bool.hh" +#include "../Utils/Exception.hh" #include "PacketTypes.hh" //#include "PacketData.mpp" @@ -159,8 +160,8 @@ namespace senf { 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 diff --git a/Packets/PacketInterpreter.hh b/Packets/PacketInterpreter.hh index 68af3da..80bb016 100644 --- a/Packets/PacketInterpreter.hh +++ b/Packets/PacketInterpreter.hh @@ -379,8 +379,8 @@ namespace senf { 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"){} }; } diff --git a/Packets/PacketRegistry.hh b/Packets/PacketRegistry.hh index bb0d4c2..8f342eb 100644 --- a/Packets/PacketRegistry.hh +++ b/Packets/PacketRegistry.hh @@ -214,8 +214,8 @@ packet of which the key is requested 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"){} }; } diff --git a/Scheduler/ClockService.cc b/Scheduler/ClockService.cc index e5f188e..3513b34 100644 --- a/Scheduler/ClockService.cc +++ b/Scheduler/ClockService.cc @@ -37,7 +37,7 @@ #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 diff --git a/Scheduler/ReadHelper.ct b/Scheduler/ReadHelper.ct index 89375b1..264d0ec 100644 --- a/Scheduler/ReadHelper.ct +++ b/Scheduler/ReadHelper.ct @@ -71,7 +71,7 @@ prefix_ void senf::ReadHelper::process(Handle handle, { try { if (event != senf::Scheduler::EV_READ) - throwErrno(EPIPE); + throw SystemException(EPIPE); std::string rcv; handle.read(rcv, maxSize_ - data_.size()); data_.append(rcv); diff --git a/Scheduler/ReadHelper.cti b/Scheduler/ReadHelper.cti index 88fadbb..92d1264 100644 --- a/Scheduler/ReadHelper.cti +++ b/Scheduler/ReadHelper.cti @@ -94,7 +94,7 @@ template prefix_ void senf::ReadHelper::throw_error() const { - if (errno_ != 0) throwErrno(errno_); + if (errno_ != 0) throw SystemException(errno_); } ///////////////////////////////cti.e/////////////////////////////////////// diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc index b19e988..6aa249c 100644 --- a/Scheduler/Scheduler.cc +++ b/Scheduler/Scheduler.cc @@ -56,24 +56,24 @@ prefix_ senf::Scheduler::Scheduler() 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) @@ -133,7 +133,7 @@ prefix_ void senf::Scheduler::do_add(int fd, FdCallback const & cb, int eventMas ++ files_; } else - throwErrno("::epoll_ctl()"); + throw SystemException("::epoll_ctl()"); } } @@ -163,7 +163,7 @@ prefix_ void senf::Scheduler::do_remove(int fd, int eventMask) } if (! file && epoll_ctl(epollFd_, action, fd, &ev) < 0) - throwErrno("::epoll_ctl()"); + throw SystemException("::epoll_ctl()"); if (file) -- files_; } @@ -179,7 +179,7 @@ prefix_ void senf::Scheduler::registerSigHandlers() if (signal == SIGCHLD) sa.sa_flags |= SA_NOCLDSTOP; if (::sigaction(signal, &sa, 0) < 0) - throwErrno(); + throw SystemException(); } } } @@ -252,7 +252,7 @@ prefix_ void senf::Scheduler::process() if (events<0) if (errno != EINTR) - throwErrno(); + throw SystemException(); eventTime_ = ClockService::now(); diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index 34e625c..8c73cda 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -295,9 +295,9 @@ namespace senf { ///< 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"){} }; ///\} diff --git a/Scheduler/WriteHelper.ct b/Scheduler/WriteHelper.ct index 17d06f4..49d096c 100644 --- a/Scheduler/WriteHelper.ct +++ b/Scheduler/WriteHelper.ct @@ -78,7 +78,7 @@ prefix_ void senf::WriteHelper::process(Handle handle, 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(); diff --git a/Scheduler/WriteHelper.cti b/Scheduler/WriteHelper.cti index 2fd9fe9..01d3e2a 100644 --- a/Scheduler/WriteHelper.cti +++ b/Scheduler/WriteHelper.cti @@ -62,7 +62,7 @@ prefix_ void senf::WriteHelper::throw_error() const { if (errno_ != 0) - throwErrno(errno_); + throw SystemException(errno_); } diff --git a/Socket/CommunicationPolicy.cc b/Socket/CommunicationPolicy.cc index 9851130..aff4c66 100644 --- a/Socket/CommunicationPolicy.cc +++ b/Socket/CommunicationPolicy.cc @@ -58,7 +58,7 @@ prefix_ int senf::ConnectedCommunicationPolicy::do_accept(FileHandle handle, case EINTR: break; default: - throwErrno(); + throw SystemException(); } } while (rv<0); return rv; diff --git a/Socket/FileHandle.cc b/Socket/FileHandle.cc index 4ce3835..3b3ef9d 100644 --- a/Socket/FileHandle.cc +++ b/Socket/FileHandle.cc @@ -44,7 +44,7 @@ prefix_ void senf::FileBody::close() { if (!valid()) - throwErrno(EBADF); + throw SystemException(EBADF); v_close(); fd_ = -1; } @@ -71,7 +71,7 @@ prefix_ void senf::FileBody::destroyClose() prefix_ void senf::FileBody::v_close() { if (::close(fd_) != 0) - throwErrno(); + throw SystemException(); } prefix_ void senf::FileBody::v_terminate() @@ -95,17 +95,17 @@ prefix_ bool senf::FileBody::blocking() 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 @@ -126,7 +126,7 @@ prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block) case EINTR: break; default: - throwErrno(); + throw SystemException(); } } while (rv<0); return rv>0; diff --git a/Socket/FileHandle.test.cc b/Socket/FileHandle.test.cc index e73f047..6835f15 100644 --- a/Socket/FileHandle.test.cc +++ b/Socket/FileHandle.test.cc @@ -51,7 +51,7 @@ namespace { { int rv = ::open(name.c_str(),O_RDWR|O_NONBLOCK) ; if (rv<0) - senf::throwErrno(); + throw senf::SystemException(); fd(rv); } }; diff --git a/Socket/NetdeviceController.cc b/Socket/NetdeviceController.cc index 5f6ab52..a11c494 100644 --- a/Socket/NetdeviceController.cc +++ b/Socket/NetdeviceController.cc @@ -96,7 +96,7 @@ prefix_ void senf::NetdeviceController::openSocket() { sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0); if ( sockfd_ < 0) - throwErrno(); + throw SystemException(); } prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr) @@ -104,14 +104,14 @@ 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//////////////////////////////////////// diff --git a/Socket/Protocols/AddressExceptions.hh b/Socket/Protocols/AddressExceptions.hh index 51338ca..ff59751 100644 --- a/Socket/Protocols/AddressExceptions.hh +++ b/Socket/Protocols/AddressExceptions.hh @@ -27,6 +27,7 @@ #define HH_AddressExceptions_ 1 // Custom includes +#include "../Utils/Exception.hh" //#include "AddressExceptions.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -34,17 +35,20 @@ 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") {} }; } diff --git a/Socket/Protocols/BSDSocketProtocol.cc b/Socket/Protocols/BSDSocketProtocol.cc index 69ba519..a051237 100644 --- a/Socket/Protocols/BSDSocketProtocol.cc +++ b/Socket/Protocols/BSDSocketProtocol.cc @@ -43,7 +43,7 @@ prefix_ std::pair senf::BSDSocketProtocol::linger() socklen_t len = sizeof(ling); ::memset(&ling,sizeof(ling),0); if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0) - throwErrno(); + throw SystemException(); return std::make_pair(ling.l_onoff, ling.l_linger); } @@ -54,7 +54,7 @@ prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout) ling.l_onoff = enable; ling.l_linger = timeout; if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0) - throwErrno(); + throw SystemException(); } /////////////////////////////////////////////////////////////////////////// @@ -65,7 +65,7 @@ prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr() int value; socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0) - throwErrno(); + throw SystemException(); return value; } @@ -74,7 +74,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool 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() @@ -83,7 +83,7 @@ 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; } @@ -92,7 +92,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::priority(boost::uint8_t value) { int ivalue (value); if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0) - throwErrno(); + throw SystemException(); } prefix_ unsigned senf::AddressableBSDSocketProtocol::rcvbuf() @@ -101,7 +101,7 @@ 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; @@ -111,7 +111,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::rcvbuf(unsigned size) const { if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0) - throwErrno(); + throw SystemException(); } prefix_ unsigned senf::AddressableBSDSocketProtocol::sndbuf() @@ -120,7 +120,7 @@ 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; @@ -130,7 +130,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::sndbuf(unsigned size) const { if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0) - throwErrno(); + throw SystemException(); } /////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/DVB/DVBDemuxHandles.cc b/Socket/Protocols/DVB/DVBDemuxHandles.cc index 3dfdd6a..2ea218e 100644 --- a/Socket/Protocols/DVB/DVBDemuxHandles.cc +++ b/Socket/Protocols/DVB/DVBDemuxHandles.cc @@ -47,7 +47,7 @@ prefix_ void senf::DVBDemuxSectionProtocol::init_client(unsigned short adapter, "/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); } @@ -61,7 +61,7 @@ prefix_ void senf::DVBDemuxSectionProtocol::setSectionFilter(struct dmx_sct_filt const { if (::ioctl(fd(), DMX_SET_FILTER, filter) < 0) - throwErrno(); + throw SystemException(); } // ---------------------------------------------------------------- @@ -73,7 +73,7 @@ prefix_ void senf::DVBDemuxPESProtocol::init_client(unsigned short adapter, unsi "/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); } @@ -87,7 +87,7 @@ prefix_ void senf::DVBDemuxPESProtocol::setPESFilter(struct dmx_pes_filter_param const { if (::ioctl(fd(), DMX_SET_PES_FILTER, filter) < 0) - throwErrno(); + throw SystemException(); } // ---------------------------------------------------------------- @@ -99,7 +99,7 @@ prefix_ void senf::DVBDvrProtocol::init_client(unsigned short adapter, unsigned "/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); } diff --git a/Socket/Protocols/DVB/DVBDemuxProtocol.cc b/Socket/Protocols/DVB/DVBDemuxProtocol.cc index 90ea73d..79023cc 100644 --- a/Socket/Protocols/DVB/DVBDemuxProtocol.cc +++ b/Socket/Protocols/DVB/DVBDemuxProtocol.cc @@ -42,21 +42,21 @@ prefix_ void senf::DVBDemuxProtocol::setBufferSize(unsigned long size) 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() diff --git a/Socket/Protocols/DVB/DVBFrontendHandle.cc b/Socket/Protocols/DVB/DVBFrontendHandle.cc index 61af0eb..96ff4f2 100644 --- a/Socket/Protocols/DVB/DVBFrontendHandle.cc +++ b/Socket/Protocols/DVB/DVBFrontendHandle.cc @@ -47,7 +47,7 @@ prefix_ void senf::DVBFrontendProtocol::init_client(uint8_t adapter, boost::uint "/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); } @@ -67,7 +67,7 @@ prefix_ void senf::DVBFrontendProtocol::signalStrength(int16_t *strength) const { if (::ioctl(fd(), FE_READ_SIGNAL_STRENGTH, strength) < 0) - throwErrno(); + throw SystemException(); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/DatagramSocketProtocol.cc b/Socket/Protocols/DatagramSocketProtocol.cc index a78b4ec..0ee1e0b 100644 --- a/Socket/Protocols/DatagramSocketProtocol.cc +++ b/Socket/Protocols/DatagramSocketProtocol.cc @@ -40,7 +40,7 @@ prefix_ struct timeval senf::DatagramSocketProtocol::timestamp() { struct timeval tv; if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0) - throwErrno(); + throw SystemException(); return tv; } diff --git a/Socket/Protocols/GenericAddressingPolicy.cc b/Socket/Protocols/GenericAddressingPolicy.cc index 9768655..5090f69 100644 --- a/Socket/Protocols/GenericAddressingPolicy.cc +++ b/Socket/Protocols/GenericAddressingPolicy.cc @@ -41,7 +41,7 @@ prefix_ void senf::GenericAddressingPolicy_Base::do_local(FileHandle handle, unsigned len) { if (::getsockname(handle.fd(),addr,&len) < 0) - throwErrno(); + throw SystemException(); } prefix_ void senf::GenericAddressingPolicy_Base::do_peer(FileHandle handle, @@ -49,7 +49,7 @@ 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, @@ -57,7 +57,7 @@ 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, @@ -72,15 +72,15 @@ 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; diff --git a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc index 9cf06b4..6e4038c 100644 --- a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc +++ b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc @@ -48,7 +48,7 @@ senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol) { int sock = ::socket(PF_INET, SOCK_RAW, protocol); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -74,7 +74,7 @@ prefix_ void senf::ConnectedRawV6SocketProtocol::init_client(int const & protoco { int sock = ::socket(PF_INET6,SOCK_RAW,protocol); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc index 2330c03..5e89b45 100644 --- a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc @@ -46,7 +46,7 @@ prefix_ void senf::ConnectedUDPv4SocketProtocol::init_client() { int sock = ::socket(PF_INET,SOCK_DGRAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -66,7 +66,7 @@ prefix_ void senf::ConnectedUDPv6SocketProtocol::init_client() { int sock = ::socket(PF_INET6,SOCK_DGRAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } diff --git a/Socket/Protocols/INet/INetProtocol.cc b/Socket/Protocols/INet/INetProtocol.cc index b7dbab4..bf32dea 100644 --- a/Socket/Protocols/INet/INetProtocol.cc +++ b/Socket/Protocols/INet/INetProtocol.cc @@ -43,7 +43,7 @@ prefix_ void senf::INetProtocol::bindInterface(std::string const & iface) 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() @@ -52,7 +52,7 @@ 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; } diff --git a/Socket/Protocols/INet/MulticastProtocol.cc b/Socket/Protocols/INet/MulticastProtocol.cc index a98c1fa..f836495 100644 --- a/Socket/Protocols/INet/MulticastProtocol.cc +++ b/Socket/Protocols/INet/MulticastProtocol.cc @@ -42,7 +42,7 @@ prefix_ void senf::MulticastProtocol::broadcastEnabled(bool v) { 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() @@ -50,7 +50,7 @@ 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; } @@ -60,7 +60,7 @@ prefix_ bool senf::MulticastProtocol::mcLoop() int value; socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0) - throwErrno(); + throw SystemException(); return value; } @@ -69,7 +69,7 @@ prefix_ void senf::MulticastProtocol::mcLoop(bool 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) @@ -80,10 +80,10 @@ 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() @@ -92,7 +92,7 @@ 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; } @@ -100,7 +100,7 @@ prefix_ void senf::MulticastProtocol::mcTTL(unsigned value) const { if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0) - throwErrno(); + throw SystemException(); } /////////////////////////////////////////////////////////////////////////// @@ -114,7 +114,7 @@ prefix_ void senf::INet4MulticastProtocol::mcAddMembership(INet4Address const & 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, @@ -126,7 +126,7 @@ prefix_ void senf::INet4MulticastProtocol::mcAddMembership(INet4Address const & 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, @@ -138,9 +138,9 @@ prefix_ void senf::INet4MulticastProtocol::mcAddMembership(INet4Address const & 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) @@ -151,7 +151,7 @@ prefix_ void senf::INet4MulticastProtocol::mcDropMembership(INet4Address const & 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, @@ -163,7 +163,7 @@ prefix_ void senf::INet4MulticastProtocol::mcDropMembership(INet4Address const & 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, @@ -175,9 +175,9 @@ prefix_ void senf::INet4MulticastProtocol::mcDropMembership(INet4Address const & 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(); } /////////////////////////////////////////////////////////////////////////// @@ -190,7 +190,7 @@ prefix_ void senf::INet6MulticastProtocol::mcAddMembership(INet6Address const & 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, @@ -200,9 +200,9 @@ prefix_ void senf::INet6MulticastProtocol::mcAddMembership(INet6Address const & 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) @@ -212,7 +212,7 @@ prefix_ void senf::INet6MulticastProtocol::mcDropMembership(INet6Address const & 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 @@ -224,9 +224,9 @@ senf::INet6MulticastProtocol::mcDropMembership(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_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throwErrno(); + throw SystemException(); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/INet/RawINetProtocol.cc b/Socket/Protocols/INet/RawINetProtocol.cc index 981fe4f..58debf9 100644 --- a/Socket/Protocols/INet/RawINetProtocol.cc +++ b/Socket/Protocols/INet/RawINetProtocol.cc @@ -40,7 +40,7 @@ prefix_ unsigned senf::RawINetProtocol::available() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throwErrno(); + throw SystemException(); return n; } diff --git a/Socket/Protocols/INet/RawINetSocketHandle.cc b/Socket/Protocols/INet/RawINetSocketHandle.cc index e140128..9083582 100644 --- a/Socket/Protocols/INet/RawINetSocketHandle.cc +++ b/Socket/Protocols/INet/RawINetSocketHandle.cc @@ -48,7 +48,7 @@ senf::RawV4SocketProtocol::init_client(int const & protocol) { int sock = ::socket(PF_INET, SOCK_RAW, protocol); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -74,7 +74,7 @@ prefix_ void senf::RawV6SocketProtocol::init_client(int const & protocol) { int sock = ::socket(PF_INET6,SOCK_RAW,protocol); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } diff --git a/Socket/Protocols/INet/TCPProtocol.cc b/Socket/Protocols/INet/TCPProtocol.cc index 340e76b..6cfe2b6 100644 --- a/Socket/Protocols/INet/TCPProtocol.cc +++ b/Socket/Protocols/INet/TCPProtocol.cc @@ -45,7 +45,7 @@ prefix_ bool senf::TCPProtocol::nodelay() int value; socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0) - throwErrno(); + throw SystemException(); return value; } @@ -54,7 +54,7 @@ prefix_ void senf::TCPProtocol::nodelay(bool value) { int ivalue (value); if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0) - throwErrno(); + throw SystemException(); } prefix_ unsigned senf::TCPProtocol::siocinq() @@ -62,7 +62,7 @@ prefix_ unsigned senf::TCPProtocol::siocinq() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throwErrno(); + throw SystemException(); return n; } @@ -71,7 +71,7 @@ prefix_ unsigned senf::TCPProtocol::siocoutq() { int n; if (::ioctl(fd(),SIOCOUTQ,&n) < 0) - throwErrno(); + throw SystemException(); return n; } diff --git a/Socket/Protocols/INet/TCPSocketHandle.cc b/Socket/Protocols/INet/TCPSocketHandle.cc index 275f91b..de403c1 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.cc +++ b/Socket/Protocols/INet/TCPSocketHandle.cc @@ -46,7 +46,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_client() { int sock = ::socket(PF_INET,SOCK_STREAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -63,7 +63,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server() { int sock = ::socket(PF_INET,SOCK_STREAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -75,7 +75,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & a serverHandle().bind(address); reuseaddr(true); if (::listen(fd(),backlog) < 0) - throwErrno(); + throw SystemException(); } /////////////////////////////////////////////////////////////////////////// @@ -86,7 +86,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_client() { int sock = ::socket(PF_INET6,SOCK_STREAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -103,7 +103,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server() { int sock = ::socket(PF_INET6,SOCK_STREAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -115,7 +115,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & a serverHandle().bind(address); reuseaddr(true); if (::listen(fd(),backlog) < 0) - throwErrno(); + throw SystemException(); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/INet/UDPProtocol.cc b/Socket/Protocols/INet/UDPProtocol.cc index 55d151b..70ff4c5 100644 --- a/Socket/Protocols/INet/UDPProtocol.cc +++ b/Socket/Protocols/INet/UDPProtocol.cc @@ -45,7 +45,7 @@ prefix_ unsigned senf::UDPProtocol::available() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throwErrno(); + throw SystemException(); return n; } diff --git a/Socket/Protocols/INet/UDPSocketHandle.cc b/Socket/Protocols/INet/UDPSocketHandle.cc index 502260b..f51fe6b 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.cc +++ b/Socket/Protocols/INet/UDPSocketHandle.cc @@ -46,7 +46,7 @@ prefix_ void senf::UDPv4SocketProtocol::init_client() { int sock = ::socket(PF_INET,SOCK_DGRAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -66,7 +66,7 @@ prefix_ void senf::UDPv6SocketProtocol::init_client() { int sock = ::socket(PF_INET6,SOCK_DGRAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } diff --git a/Socket/Protocols/Raw/PacketSocketHandle.cc b/Socket/Protocols/Raw/PacketSocketHandle.cc index 05eef45..fc0c1f9 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.cc +++ b/Socket/Protocols/Raw/PacketSocketHandle.cc @@ -50,7 +50,7 @@ prefix_ void senf::PacketProtocol::init_client(SocketType type, int protocol) protocol = ETH_P_ALL; int sock = ::socket(PF_PACKET, socktype, htons(protocol)); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } @@ -61,7 +61,7 @@ prefix_ unsigned senf::PacketProtocol::available() return 0; ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); if (l < 0) - throwErrno(); + throw SystemException(); return l; } @@ -78,14 +78,14 @@ namespace { 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(); } } diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.cc b/Socket/Protocols/Raw/TunTapSocketHandle.cc index 2cf8670..564a8b5 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.cc @@ -50,7 +50,7 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name, { 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; @@ -58,7 +58,7 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name, 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); } @@ -69,7 +69,7 @@ prefix_ unsigned senf::TapProtocol::available() return 0; ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); if (l < 0) - //throwErrno(); + //throw SystemException(); return 1588; return l; } @@ -84,7 +84,7 @@ prefix_ unsigned senf::TapProtocol::available() return 0; int n; if (::ioctl(body().fd(),SIOCINQ,&n) < 0) - throwErrno(); + throw SystemException(); return n; } */ diff --git a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc index f5429aa..efe1d7f 100644 --- a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc +++ b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc @@ -40,7 +40,7 @@ prefix_ void senf::ConnectedUNDatagramSocketProtocol::init_client() const { int sock = ::socket(PF_UNIX,SOCK_DGRAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.cc index 43ecc00..6b1c91d 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.cc +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.cc @@ -41,7 +41,7 @@ prefix_ void senf::UNDatagramSocketProtocol::init_client() const { int sock = ::socket(PF_UNIX,SOCK_DGRAM,0); if (sock < 0) - throwErrno(); + throw SystemException(); fd(sock); } diff --git a/Socket/Protocols/UN/UNProtocol.cc b/Socket/Protocols/UN/UNProtocol.cc index 4e0d959..f86458c 100644 --- a/Socket/Protocols/UN/UNProtocol.cc +++ b/Socket/Protocols/UN/UNProtocol.cc @@ -41,7 +41,7 @@ prefix_ unsigned senf::UNProtocol::available() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throwErrno(); + throw SystemException(); return n; } diff --git a/Socket/ReadWritePolicy.cc b/Socket/ReadWritePolicy.cc index 6be00b6..d53a959 100644 --- a/Socket/ReadWritePolicy.cc +++ b/Socket/ReadWritePolicy.cc @@ -53,7 +53,7 @@ prefix_ unsigned senf::ReadablePolicy::read(FileHandle handle, char * buffer, rv = 0; break; default: - throwErrno(); + throw SystemException(); } } while (rv<0); return rv; @@ -74,7 +74,7 @@ prefix_ unsigned senf::ReadablePolicy::do_readfrom(FileHandle handle, char * buf rv = 0; break; default: - throwErrno(); + throw SystemException(); } } while (rv<0); return rv; @@ -100,7 +100,7 @@ prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle handle, char const * rv = 0; break; default: - throwErrno(); + throw SystemException(); } } while (rv<0); return rv; @@ -121,7 +121,7 @@ prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle handle, rv = 0; break; default: - throwErrno(); + throw SystemException(); } } while (rv<0); return rv; diff --git a/Socket/SocketProtocol.cc b/Socket/SocketProtocol.cc index ca28664..672f21f 100644 --- a/Socket/SocketProtocol.cc +++ b/Socket/SocketProtocol.cc @@ -38,9 +38,9 @@ prefix_ void senf::SocketProtocol::close() const { if (::shutdown(body().fd(),SHUT_RDWR) < 0) - throwErrno(); + throw SystemException(); if (::close(body().fd()) < 0) - throwErrno(); + throw SystemException(); } prefix_ void senf::SocketProtocol::terminate() diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index 58b880f..73fbf5d 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -45,8 +45,8 @@ #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 @@ -83,7 +83,7 @@ prefix_ void senf::Daemon::openLog() 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_) @@ -91,7 +91,7 @@ prefix_ void senf::Daemon::openLog() 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; } } @@ -139,7 +139,7 @@ prefix_ void senf::Daemon::detach() while (! signaled) { ::sigsuspend(&waitsig); if (errno != EINTR) - throwErrno("::sigsuspend()"); + throw SystemException("::sigsuspend()"); } LIBC_CALL( ::sigaction, (SIGUSR1, &oldact, 0) ); @@ -326,7 +326,7 @@ prefix_ bool senf::Daemon::pidfileCreate() if (::link(tempname.c_str(), pidfile_.c_str()) < 0) { if (errno != EEXIST) - throwErrno("::link()"); + throw SystemException("::link()"); } else { struct ::stat s; @@ -356,7 +356,7 @@ prefix_ bool senf::Daemon::pidfileCreate() 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; } @@ -419,7 +419,7 @@ prefix_ void senf::detail::DaemonWatcher::pipeClosed(int id) 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)); @@ -436,7 +436,7 @@ prefix_ void senf::detail::DaemonWatcher::sigChld() 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)); @@ -487,7 +487,7 @@ prefix_ void senf::detail::DaemonWatcher::Forwarder::readData(Scheduler::EventId while (1) { n = ::read(src_,buf,1024); if (n<0) { - if (errno != EINTR) throwErrno("::read()"); + if (errno != EINTR) throw SystemException("::read()"); } else break; } @@ -531,7 +531,7 @@ prefix_ void senf::detail::DaemonWatcher::Forwarder::writeData(Scheduler::EventI 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; diff --git a/Utils/Daemon/Daemon.test.cc b/Utils/Daemon/Daemon.test.cc index 1a5990b..e456939 100644 --- a/Utils/Daemon/Daemon.test.cc +++ b/Utils/Daemon/Daemon.test.cc @@ -80,12 +80,12 @@ namespace { 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; } diff --git a/Utils/Exception.cc b/Utils/Exception.cc index 06d531c..5e69277 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -31,38 +31,17 @@ #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(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//////////////////////////////////////// diff --git a/Utils/Exception.cci b/Utils/Exception.cci index 40d89a5..84f5d7b 100644 --- a/Utils/Exception.cci +++ b/Utils/Exception.cci @@ -27,25 +27,27 @@ #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() @@ -80,19 +82,12 @@ prefix_ senf::SystemException::~SystemException() 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/////////////////////////////////////// diff --git a/Utils/Exception.cti b/Utils/Exception.cti index 88aaca8..3588cdc 100644 --- a/Utils/Exception.cti +++ b/Utils/Exception.cti @@ -26,23 +26,17 @@ //#include "Exception.ih" // Custom includes +#include #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// -template -prefix_ senf::ErrnoException::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 -prefix_ senf::ErrnoException::ErrnoException(ErrnoException const & other) - : SystemException(other) -{} +template +prefix_ senf::Exception & senf::Exception::operator<<(Arg const & arg) +{ + message_ += boost::lexical_cast(arg); + return *this; +} /////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 9cf7c8a..0675aee 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -38,147 +38,143 @@ //#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 & 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 Boost.Format: \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 + 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 boost::lexical_cast 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 - 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_; + }; } diff --git a/Utils/Exception.test.cc b/Utils/Exception.test.cc index 686919a..5b2b95f 100644 --- a/Utils/Exception.test.cc +++ b/Utils/Exception.test.cc @@ -39,23 +39,18 @@ 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" ); } } diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 0fec6a5..cbb72c5 100644 --- a/Utils/Logger/Target.hh +++ b/Utils/Logger/Target.hh @@ -35,6 +35,7 @@ #include "../mpl.hh" #include "StreamRegistry.hh" #include "AreaRegistry.hh" +#include "../Exception.hh" //#include "Target.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -341,14 +342,14 @@ namespace log { ///\} /** \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 diff --git a/Utils/SConscript b/Utils/SConscript index 75a2b96..a39e7f6 100644 --- a/Utils/SConscript +++ b/Utils/SConscript @@ -1,14 +1,15 @@ # -*- 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 ) diff --git a/admin/build.sh b/admin/build.sh index 87e2587..cd69e9b 100755 --- a/admin/build.sh +++ b/admin/build.sh @@ -16,7 +16,7 @@ echo -n '# Starting build at '; date --utc 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'