From: g0dil Date: Fri, 7 Mar 2008 23:06:27 +0000 (+0000) Subject: Utils: Implement helper macros to add file/line information to SystemException's X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=034f9bec0a66d26314fb6ebc83dedf1618a2c19d;p=senf.git Utils: Implement helper macros to add file/line information to SystemException's Socket: Fix NetDeviceController.test.cc (use 'lo' interface instead of 'wlan0' Socket/Protocols/MPEGDVBbundle: Fix TransportPacket.test.cc (add 0 to constant to fix link error) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@736 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/MPEGDVBBundle/TransportPacket.test.cc b/Packets/MPEGDVBBundle/TransportPacket.test.cc index fc843de..91f0f28 100644 --- a/Packets/MPEGDVBBundle/TransportPacket.test.cc +++ b/Packets/MPEGDVBBundle/TransportPacket.test.cc @@ -69,14 +69,14 @@ BOOST_AUTO_UNIT_TEST(transportPacket_packet) senf::TransportPacket p (senf::TransportPacket::create(data)); - BOOST_CHECK_EQUAL( p->sync_byte(), TransportPacketType::SYNC_BYTE ); - BOOST_CHECK( ! p->transport_error_indicator() ); - BOOST_CHECK( p->pusi() ); - BOOST_CHECK( ! p->transport_priority() ); - BOOST_CHECK_EQUAL( p->pid(), 0x010fu ); - BOOST_CHECK_EQUAL( p->transport_scrmbl_ctrl(), 0x0u ); - BOOST_CHECK_EQUAL( p->adaptation_field_ctrl(), 0x1u ); - BOOST_CHECK_EQUAL( p->continuity_counter(), 0x0eu ); + BOOST_CHECK_EQUAL( p->sync_byte(), TransportPacketType::SYNC_BYTE+0 ); + BOOST_CHECK( ! p->transport_error_indicator() ); + BOOST_CHECK( p->pusi() ); + BOOST_CHECK( ! p->transport_priority() ); + BOOST_CHECK_EQUAL( p->pid(), 0x010fu ); + BOOST_CHECK_EQUAL( p->transport_scrmbl_ctrl(), 0x0u ); + BOOST_CHECK_EQUAL( p->adaptation_field_ctrl(), 0x1u ); + BOOST_CHECK_EQUAL( p->continuity_counter(), 0x0eu ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Scheduler/ClockService.cc b/Scheduler/ClockService.cc index 3513b34..97c5fbc 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) throw SystemException(# op, errno) +#define CheckError(op,args) if (op args < 0) SENF_THROW_SYSTEM_EXCEPTION(# op) /////////////////////////////////////////////////////////////////////////// // senf::ClockService::Impl diff --git a/Scheduler/ReadHelper.ct b/Scheduler/ReadHelper.ct index 264d0ec..25f0364 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) - throw SystemException(EPIPE); + throw SystemException(EPIPE SENF_EXC_DEBUGINFO); std::string rcv; handle.read(rcv, maxSize_ - data_.size()); data_.append(rcv); diff --git a/Scheduler/ReadHelper.cti b/Scheduler/ReadHelper.cti index 92d1264..d491f64 100644 --- a/Scheduler/ReadHelper.cti +++ b/Scheduler/ReadHelper.cti @@ -94,7 +94,7 @@ template prefix_ void senf::ReadHelper::throw_error() const { - if (errno_ != 0) throw SystemException(errno_); + if (errno_ != 0) throw SystemException(errno_ SENF_EXC_DEBUGINFO); } ///////////////////////////////cti.e/////////////////////////////////////// diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc index 6aa249c..758b980 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); if (::pipe(sigpipe_) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); int flags (::fcntl(sigpipe_[1],F_GETFL)); if (flags < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); flags |= O_NONBLOCK; if (::fcntl(sigpipe_[1], F_SETFL, flags) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); ::epoll_event ev; ::memset(&ev, 0, sizeof(ev)); ev.events = EV_READ; ev.data.fd = sigpipe_[0]; if (::epoll_ctl(epollFd_, EPOLL_CTL_ADD, sigpipe_[0], &ev) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ void senf::Scheduler::registerSignal(unsigned signal, SimpleCallback const & cb) @@ -133,7 +133,7 @@ prefix_ void senf::Scheduler::do_add(int fd, FdCallback const & cb, int eventMas ++ files_; } else - throw SystemException("::epoll_ctl()"); + SENF_THROW_SYSTEM_EXCEPTION("::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) - throw SystemException("::epoll_ctl()"); + SENF_THROW_SYSTEM_EXCEPTION("::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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } } } @@ -252,7 +252,7 @@ prefix_ void senf::Scheduler::process() if (events<0) if (errno != EINTR) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); eventTime_ = ClockService::now(); diff --git a/Scheduler/WriteHelper.ct b/Scheduler/WriteHelper.ct index 49d096c..fadb65f 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) - throw SystemException(EPIPE); + throw SystemException(EPIPE SENF_EXC_DEBUGINFO); 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 01d3e2a..c67b4d8 100644 --- a/Scheduler/WriteHelper.cti +++ b/Scheduler/WriteHelper.cti @@ -62,7 +62,7 @@ prefix_ void senf::WriteHelper::throw_error() const { if (errno_ != 0) - throw SystemException(errno_); + throw SystemException(errno_ SENF_EXC_DEBUGINFO); } diff --git a/Socket/CommunicationPolicy.cc b/Socket/CommunicationPolicy.cc index d175b58..ef0bba5 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: - throw SystemException("ConnectedCommunicationPolicy::do_accept failed."); + SENF_THROW_SYSTEM_EXCEPTION("ConnectedCommunicationPolicy::do_accept failed."); } } while (rv<0); return rv; diff --git a/Socket/FileHandle.cc b/Socket/FileHandle.cc index 3b3ef9d..2b1e176 100644 --- a/Socket/FileHandle.cc +++ b/Socket/FileHandle.cc @@ -44,7 +44,7 @@ prefix_ void senf::FileBody::close() { if (!valid()) - throw SystemException(EBADF); + throw SystemException(EBADF SENF_EXC_DEBUGINFO); v_close(); fd_ = -1; } @@ -71,7 +71,7 @@ prefix_ void senf::FileBody::destroyClose() prefix_ void senf::FileBody::v_close() { if (::close(fd_) != 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } 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) throw SystemException(); + if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION(""); return ! (flags & O_NONBLOCK); } prefix_ void senf::FileBody::blocking(bool status) { int flags = ::fcntl(fd(),F_GETFL); - if (flags < 0) throw SystemException(); + if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION(""); if (status) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; - if (::fcntl(fd(), F_SETFL, flags) < 0) throw SystemException(); + if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION(""); } /* We don't take POLLIN/POLLOUT as argument to avoid having to include @@ -126,7 +126,7 @@ prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block) case EINTR: break; default: - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv>0; diff --git a/Socket/NetdeviceController.cc b/Socket/NetdeviceController.cc index 23ea64a..07466c6 100644 --- a/Socket/NetdeviceController.cc +++ b/Socket/NetdeviceController.cc @@ -109,7 +109,7 @@ prefix_ void senf::NetdeviceController::openSocket() { sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0); if ( sockfd_ < 0) - throw SystemException("Could not open socket for NetdeviceController."); + SENF_THROW_SYSTEM_EXCEPTION("Could not open socket for NetdeviceController."); } prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr) @@ -118,7 +118,7 @@ prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr) ::memset( &ifr, 0, sizeof(ifr)); ifr.ifr_ifindex = ifindex_; if ( ::ioctl( sockfd_, SIOCGIFNAME, &ifr ) < 0 ) - throw SystemException("NetdeviceController") + SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController") << " could not discover the name of the interface with index " << ifindex_ << "."; } @@ -126,7 +126,7 @@ prefix_ void senf::NetdeviceController::doIoctl(ifreq& ifr, int request) const { if ( ::ioctl( sockfd_, request, &ifr ) < 0 ) - throw SystemException("NetdeviceController::doIoctl failed."); + SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController::doIoctl failed."); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/NetdeviceController.test.cc b/Socket/NetdeviceController.test.cc index 9992830..784ea5c 100644 --- a/Socket/NetdeviceController.test.cc +++ b/Socket/NetdeviceController.test.cc @@ -37,7 +37,7 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) { - senf::NetdeviceController ctrl ("wlan0"); + senf::NetdeviceController ctrl ("lo"); std::cout << "name: " << ctrl.interfaceName() << "\n"; senf::MACAddress oldAddr(ctrl.hardwareAddress()); diff --git a/Socket/Protocols/BSDSocketProtocol.cc b/Socket/Protocols/BSDSocketProtocol.cc index f1423f9..79754e5 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ boost::uint8_t senf::BSDSocketProtocol::priority() @@ -63,7 +63,7 @@ prefix_ boost::uint8_t senf::BSDSocketProtocol::priority() int value; socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } @@ -72,7 +72,7 @@ prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value) { int ivalue (value); if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ unsigned senf::BSDSocketProtocol::rcvbuf() @@ -81,7 +81,7 @@ prefix_ unsigned senf::BSDSocketProtocol::rcvbuf() unsigned size; socklen_t len (sizeof(size)); if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); // Linux doubles the bufer size on setting the RCVBUF to cater for internal // headers. We fix this up here .. (see lkml FAQ) return size/2; @@ -91,7 +91,7 @@ prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size) const { if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ unsigned senf::BSDSocketProtocol::sndbuf() @@ -100,7 +100,7 @@ prefix_ unsigned senf::BSDSocketProtocol::sndbuf() unsigned size; socklen_t len (sizeof(size)); if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); // Linux doubles the bufer size on setting the SNDBUF to cater for internal // headers. We fix this up here .. (see lkml FAQ) return size/2; @@ -110,7 +110,7 @@ prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size) const { if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////////////////////////////////////////////////// @@ -121,7 +121,7 @@ prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr() int value; socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } @@ -130,7 +130,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value) { int ivalue (value); if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/DVB/DVBDemuxHandles.cc b/Socket/Protocols/DVB/DVBDemuxHandles.cc index 788069f..d5343e3 100644 --- a/Socket/Protocols/DVB/DVBDemuxHandles.cc +++ b/Socket/Protocols/DVB/DVBDemuxHandles.cc @@ -47,7 +47,7 @@ prefix_ void senf::DVBDemuxSectionSocketProtocol::init_client(unsigned short ada "/dev/dvb/adapter%d/demux%d") % adapter % device); int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK); if (f < 0){ - throw SystemException("Could not open demux device of DVB adapter ") << devDemux << "."; + SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << "."; } fd(f); } @@ -62,7 +62,7 @@ prefix_ void senf::DVBDemuxSectionSocketProtocol::setSectionFilter(struct dmx_sc const { if (::ioctl(fd(), DMX_SET_FILTER, filter) < 0) - throw SystemException("Could not set section filter of DVB adapter."); + SENF_THROW_SYSTEM_EXCEPTION("Could not set section filter of DVB adapter."); } // ---------------------------------------------------------------- @@ -74,7 +74,7 @@ prefix_ void senf::DVBDemuxPESSocketProtocol::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) - throw SystemException( "Could not open demux device of DVB adapter ") << devDemux << "."; + SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << "."; fd(f); } @@ -88,7 +88,7 @@ prefix_ void senf::DVBDemuxPESSocketProtocol::setPESFilter(struct dmx_pes_filter const { if (::ioctl(fd(), DMX_SET_PES_FILTER, filter) < 0) - throw SystemException("Could not set PES filter of DVB adapter."); + SENF_THROW_SYSTEM_EXCEPTION("Could not set PES filter of DVB adapter."); } // ---------------------------------------------------------------- @@ -100,7 +100,7 @@ prefix_ void senf::DVBDvrSocketProtocol::init_client(unsigned short adapter, uns "/dev/dvb/adapter%d/dvr%d") % adapter % device); int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK); if (f < 0) - throw SystemException( "Could not open dvr device of DVB adapter ") << devDvr << "."; + SENF_THROW_SYSTEM_EXCEPTION("Could not open dvr device of DVB adapter ") << devDvr << "."; fd(f); } diff --git a/Socket/Protocols/DVB/DVBDemuxSocketProtocol.cc b/Socket/Protocols/DVB/DVBDemuxSocketProtocol.cc index 0059e39..1394a19 100644 --- a/Socket/Protocols/DVB/DVBDemuxSocketProtocol.cc +++ b/Socket/Protocols/DVB/DVBDemuxSocketProtocol.cc @@ -42,7 +42,7 @@ prefix_ void senf::DVBDemuxSocketProtocol::setBufferSize(unsigned long size) const { if (::ioctl(fd(), DMX_SET_BUFFER_SIZE, size) < 0) - throw SystemException() + SENF_THROW_SYSTEM_EXCEPTION("") << "Could not set the size of the buffer on DVB adapter. requested size: " << size << "."; } @@ -51,14 +51,14 @@ prefix_ void senf::DVBDemuxSocketProtocol::startFiltering() const { if (::ioctl(fd(), DMX_START) < 0) - throw SystemException("Could not start filtering operation on DVB adapter."); + SENF_THROW_SYSTEM_EXCEPTION("Could not start filtering operation on DVB adapter."); } prefix_ void senf::DVBDemuxSocketProtocol::stopFiltering() const { if (::ioctl(fd(), DMX_STOP) < 0) - throw SystemException("Could not stop filtering operation on DVB adapter."); + SENF_THROW_SYSTEM_EXCEPTION("Could not stop filtering operation on DVB adapter."); } prefix_ bool senf::DVBDemuxSocketProtocol::eof() diff --git a/Socket/Protocols/DVB/DVBFrontendHandle.cc b/Socket/Protocols/DVB/DVBFrontendHandle.cc index 7933b71..db5be7e 100644 --- a/Socket/Protocols/DVB/DVBFrontendHandle.cc +++ b/Socket/Protocols/DVB/DVBFrontendHandle.cc @@ -47,7 +47,7 @@ prefix_ void senf::DVBFrontendSocketProtocol::init_client(uint8_t adapter, boost "/dev/dvb/adapter%d/frontend%d") % adapter % device); int f = open(devFrontend.c_str(), O_RDONLY | O_NONBLOCK); if (f < 0) - throw SystemException() << "Could not open frontend device of DVB adapter " << devFrontend << "."; + SENF_THROW_SYSTEM_EXCEPTION("") << "Could not open frontend device of DVB adapter " << devFrontend << "."; fd(f); } @@ -68,7 +68,7 @@ prefix_ void senf::DVBFrontendSocketProtocol::signalStrength(int16_t *strength) const { if (::ioctl(fd(), FE_READ_SIGNAL_STRENGTH, strength) < 0) - throw SystemException( "Could not get signal strength of DVB adapter."); + SENF_THROW_SYSTEM_EXCEPTION("Could not get signal strength of DVB adapter."); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/DatagramSocketProtocol.cc b/Socket/Protocols/DatagramSocketProtocol.cc index 0ee1e0b..a0ac877 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return tv; } diff --git a/Socket/Protocols/GenericAddressingPolicy.cc b/Socket/Protocols/GenericAddressingPolicy.cc index 5090f69..9031707 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); if (err != 0) - throw SystemException(err); + throw SystemException(err SENF_EXC_DEBUGINFO); return; } case EINTR: break; default: - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } else return; diff --git a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc index 6e4038c..45715cb 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); fd(sock); } diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc index bc5432a..f65299d 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) - throw SystemException("::socket(PF_INET,SOCK_DGRAM,0) failed."); + SENF_THROW_SYSTEM_EXCEPTION("::socket(PF_INET,SOCK_DGRAM,0) failed."); fd(sock); } @@ -66,7 +66,7 @@ prefix_ void senf::ConnectedUDPv6SocketProtocol::init_client() { int sock = ::socket(PF_INET6,SOCK_DGRAM,0); if (sock < 0) - throw SystemException("::socket(PF_INET6,SOCK_DGRAM,0) failed."); + SENF_THROW_SYSTEM_EXCEPTION("::socket(PF_INET6,SOCK_DGRAM,0) failed."); fd(sock); } diff --git a/Socket/Protocols/INet/INetSocketProtocol.cc b/Socket/Protocols/INet/INetSocketProtocol.cc index 207c5a4..c83d53f 100644 --- a/Socket/Protocols/INet/INetSocketProtocol.cc +++ b/Socket/Protocols/INet/INetSocketProtocol.cc @@ -43,7 +43,7 @@ prefix_ void senf::INetSocketProtocol::bindInterface(std::string const & iface) const { if (::setsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) < 0) - throw SystemException("::setsockopt(SO_BINDTODEVICE)"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(SO_BINDTODEVICE)"); } prefix_ std::string senf::INetSocketProtocol::bindInterface() @@ -52,7 +52,7 @@ prefix_ std::string senf::INetSocketProtocol::bindInterface() socklen_t size (sizeof(iface)); ::memset(iface, 0, sizeof(iface)); if (::getsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface, &size) < 0) - throw SystemException("::getsockopt(SO_BINDTODEVICE)"); + SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_BINDTODEVICE)"); iface[size < IFNAMSIZ ? size : IFNAMSIZ-1] = 0; return iface; } diff --git a/Socket/Protocols/INet/MulticastSocketProtocol.cc b/Socket/Protocols/INet/MulticastSocketProtocol.cc index 1712748..8d47679 100644 --- a/Socket/Protocols/INet/MulticastSocketProtocol.cc +++ b/Socket/Protocols/INet/MulticastSocketProtocol.cc @@ -30,6 +30,7 @@ #include #include #include // for if_nametoindex +#include "../../../Utils/Exception.hh" //#include "MulticastSocketProtocol.mpp" #define prefix_ @@ -43,7 +44,7 @@ prefix_ void senf::MulticastSocketProtocol::broadcastEnabled(bool v) { int ivalue (v); if (::setsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &ivalue, sizeof(ivalue)) < 0) - throw SystemException("::setsockopt(SO_BROADCAST)"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(SO_BROADCAST)"); } prefix_ bool senf::MulticastSocketProtocol::broadcastEnabled() @@ -52,7 +53,7 @@ prefix_ bool senf::MulticastSocketProtocol::broadcastEnabled() int value (0); ::socklen_t len (sizeof(value)); if (::getsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &value, &len) < 0) - throw SystemException("::getsockopt(SO_BROADCAST)"); + SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_BROADCAST)"); return value; } @@ -62,7 +63,7 @@ prefix_ bool senf::MulticastSocketProtocol::mcLoop() int value (0); socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } @@ -71,7 +72,7 @@ prefix_ void senf::MulticastSocketProtocol::mcLoop(bool value) { int ivalue (value); if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface) @@ -82,10 +83,10 @@ prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface) if (!iface.empty()) { mreqn.imr_ifindex = if_nametoindex(iface.c_str()); if (mreqn.imr_ifindex == 0) - throw SystemException(EINVAL); + throw SystemException(EINVAL SENF_EXC_DEBUGINFO); } if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ unsigned senf::MulticastSocketProtocol::mcTTL() @@ -94,7 +95,7 @@ prefix_ unsigned senf::MulticastSocketProtocol::mcTTL() int value (0); socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } @@ -102,7 +103,7 @@ prefix_ void senf::MulticastSocketProtocol::mcTTL(unsigned value) const { if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////////////////////////////////////////////////// @@ -116,7 +117,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address co mreqn.imr_address.s_addr = htons(INADDR_ANY); mreqn.imr_ifindex = 0; if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP)"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_ADD_MEMBERSHIP)"); } prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address const & mcAddr, @@ -128,7 +129,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address co mreqn.imr_address.s_addr = localAddr.inaddr(); mreqn.imr_ifindex = 0; if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_ADD_MEMBERSHIP"); } prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address const & mcAddr, @@ -140,9 +141,9 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcAddMembership(INet4Address co mreqn.imr_address.s_addr = htons(INADDR_ANY); mreqn.imr_ifindex = if_nametoindex(iface.c_str()); if (mreqn.imr_ifindex == 0) - throw SystemException("::if_nametoindex()",ENOENT); + throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO); if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException("::setsockopt(IP_ADD_MEMBERSHIP"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_ADD_MEMBERSHIP"); } prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr) @@ -153,7 +154,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address c mreqn.imr_address.s_addr = htons(INADDR_ANY); mreqn.imr_ifindex = 0; if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr, @@ -165,7 +166,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address c mreqn.imr_address.s_addr = localAddr.inaddr(); mreqn.imr_ifindex = 0; if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr, @@ -177,9 +178,9 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address c mreqn.imr_address.s_addr = htons(INADDR_ANY); mreqn.imr_ifindex = if_nametoindex(iface.c_str()); if (mreqn.imr_ifindex == 0) - throw SystemException("::if_nametoindex()",ENOENT); + throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO); if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////////////////////////////////////////////////// @@ -192,7 +193,7 @@ prefix_ void senf::INet6MulticastSocketProtocol::mcAddMembership(INet6Address co std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr); mreqn.ipv6mr_interface = 0; if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException("::setsockopt(IPV6_ADD_MEMBERSHIP"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_ADD_MEMBERSHIP"); } prefix_ void senf::INet6MulticastSocketProtocol::mcAddMembership(INet6Address const & mcAddr, @@ -202,9 +203,9 @@ prefix_ void senf::INet6MulticastSocketProtocol::mcAddMembership(INet6Address co std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr); mreqn.ipv6mr_interface = if_nametoindex(iface.c_str()); if (mreqn.ipv6mr_interface == 0) - throw SystemException("::if_nametoindex()",ENOENT); + throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO); if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException("::setsockopt(IPV6_ADD_MEMBERSHIP"); + SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_ADD_MEMBERSHIP"); } prefix_ void senf::INet6MulticastSocketProtocol::mcDropMembership(INet6Address const & mcAddr) @@ -214,7 +215,7 @@ prefix_ void senf::INet6MulticastSocketProtocol::mcDropMembership(INet6Address c std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr); mreqn.ipv6mr_interface = 0; if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ void @@ -226,9 +227,9 @@ senf::INet6MulticastSocketProtocol::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) - throw SystemException("::if_nametoindex()",ENOENT); + throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO); if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/INet/RawINetSocketHandle.cc b/Socket/Protocols/INet/RawINetSocketHandle.cc index 9083582..eb39628 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); fd(sock); } diff --git a/Socket/Protocols/INet/RawINetSocketProtocol.cc b/Socket/Protocols/INet/RawINetSocketProtocol.cc index 636c20f..8a676be 100644 --- a/Socket/Protocols/INet/RawINetSocketProtocol.cc +++ b/Socket/Protocols/INet/RawINetSocketProtocol.cc @@ -40,7 +40,7 @@ prefix_ unsigned senf::RawINetSocketProtocol::available() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return n; } diff --git a/Socket/Protocols/INet/TCPSocketHandle.cc b/Socket/Protocols/INet/TCPSocketHandle.cc index de403c1..b52cf4c 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); fd(sock); } @@ -63,7 +63,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server() { int sock = ::socket(PF_INET,SOCK_STREAM,0); if (sock < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } /////////////////////////////////////////////////////////////////////////// @@ -86,7 +86,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_client() { int sock = ::socket(PF_INET6,SOCK_STREAM,0); if (sock < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); fd(sock); } @@ -103,7 +103,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server() { int sock = ::socket(PF_INET6,SOCK_STREAM,0); if (sock < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/Protocols/INet/TCPSocketProtocol.cc b/Socket/Protocols/INet/TCPSocketProtocol.cc index 4888934..a11ac98 100644 --- a/Socket/Protocols/INet/TCPSocketProtocol.cc +++ b/Socket/Protocols/INet/TCPSocketProtocol.cc @@ -45,7 +45,7 @@ prefix_ bool senf::TCPSocketProtocol::nodelay() int value; socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return value; } @@ -54,7 +54,7 @@ prefix_ void senf::TCPSocketProtocol::nodelay(bool value) { int ivalue (value); if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ unsigned senf::TCPSocketProtocol::siocinq() @@ -62,7 +62,7 @@ prefix_ unsigned senf::TCPSocketProtocol::siocinq() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return n; } @@ -71,7 +71,7 @@ prefix_ unsigned senf::TCPSocketProtocol::siocoutq() { int n; if (::ioctl(fd(),SIOCOUTQ,&n) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return n; } diff --git a/Socket/Protocols/INet/UDPSocketHandle.cc b/Socket/Protocols/INet/UDPSocketHandle.cc index f51fe6b..827738b 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) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); fd(sock); } @@ -66,7 +66,7 @@ prefix_ void senf::UDPv6SocketProtocol::init_client() { int sock = ::socket(PF_INET6,SOCK_DGRAM,0); if (sock < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); fd(sock); } diff --git a/Socket/Protocols/INet/UDPSocketProtocol.cc b/Socket/Protocols/INet/UDPSocketProtocol.cc index 4c61e76..8d95a4f 100644 --- a/Socket/Protocols/INet/UDPSocketProtocol.cc +++ b/Socket/Protocols/INet/UDPSocketProtocol.cc @@ -45,7 +45,7 @@ prefix_ unsigned senf::UDPSocketProtocol::available() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return n; } diff --git a/Socket/Protocols/Raw/PacketSocketHandle.cc b/Socket/Protocols/Raw/PacketSocketHandle.cc index 3a7eaad..224b469 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.cc +++ b/Socket/Protocols/Raw/PacketSocketHandle.cc @@ -50,7 +50,7 @@ prefix_ void senf::PacketSocketProtocol::init_client(SocketType type, int protoc protocol = ETH_P_ALL; int sock = ::socket(PF_PACKET, socktype, htons(protocol)); if (sock < 0) - throw SystemException("::socket(...) failed."); + SENF_THROW_SYSTEM_EXCEPTION("::socket(...) failed."); fd(sock); } @@ -61,7 +61,7 @@ prefix_ unsigned senf::PacketSocketProtocol::available() return 0; ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); if (l < 0) - throw SystemException("::recv(socket_fd) failed."); + SENF_THROW_SYSTEM_EXCEPTION("::recv(socket_fd) failed."); return l; } diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.cc b/Socket/Protocols/Raw/TunTapSocketHandle.cc index cd68e06..58170a0 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.cc @@ -50,7 +50,7 @@ prefix_ void senf::TapSocketProtocol::init_client(std::string const & interface_ { int f; if ( (f = ::open("/dev/net/tun", O_RDWR)) < 0 ) - throw SystemException( "Could not open tap control device: /dev/net/tun."); + SENF_THROW_SYSTEM_EXCEPTION("Could not open tap control device: /dev/net/tun."); struct ifreq ifr; ::memset( &ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP; @@ -58,7 +58,7 @@ prefix_ void senf::TapSocketProtocol::init_client(std::string const & interface_ ifr.ifr_flags |= IFF_NO_PI; interface_name.copy( ifr.ifr_name, IFNAMSIZ); if (::ioctl(f, TUNSETIFF, (void *) &ifr) < 0 ) - throw SystemException( "Could not create tap device: ") << ifr.ifr_name << "."; + SENF_THROW_SYSTEM_EXCEPTION( "Could not create tap device: ") << ifr.ifr_name << "."; fd(f); } @@ -69,7 +69,7 @@ prefix_ unsigned senf::TapSocketProtocol::available() return 0; ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); if (l < 0) - //throw SystemException(); + //SENF_THROW_SYSTEM_EXCEPTION(""); return 1588; return l; } @@ -84,7 +84,7 @@ prefix_ unsigned senf::TapSocketProtocol::available() return 0; int n; if (::ioctl(body().fd(),SIOCINQ,&n) < 0) - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); return n; } */ diff --git a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc index 21e7ddc..af7fd44 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) - throw SystemException( "Could not create socket(PF_UNIX,SOCK_DGRAM,0)." ); + SENF_THROW_SYSTEM_EXCEPTION("Could not create socket(PF_UNIX,SOCK_DGRAM,0)."); fd(sock); } diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.cc index a84d8ec..895cf63 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) - throw SystemException( "Could not create socket(PF_UNIX,SOCK_DGRAM,0)." ); + SENF_THROW_SYSTEM_EXCEPTION("Could not create socket(PF_UNIX,SOCK_DGRAM,0)."); fd(sock); } diff --git a/Socket/Protocols/UN/UNSocketProtocol.cc b/Socket/Protocols/UN/UNSocketProtocol.cc index 2e9404d..c9db377 100644 --- a/Socket/Protocols/UN/UNSocketProtocol.cc +++ b/Socket/Protocols/UN/UNSocketProtocol.cc @@ -42,7 +42,7 @@ prefix_ unsigned senf::UNSocketProtocol::available() { int n; if (::ioctl(fd(),SIOCINQ,&n) < 0) - throw SystemException("Could not call available() on UNSocket."); + SENF_THROW_SYSTEM_EXCEPTION("Could not call available() on UNSocket."); return n; } diff --git a/Socket/ReadWritePolicy.cc b/Socket/ReadWritePolicy.cc index d53a959..c842604 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: - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv; @@ -74,7 +74,7 @@ prefix_ unsigned senf::ReadablePolicy::do_readfrom(FileHandle handle, char * buf rv = 0; break; default: - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv; @@ -100,7 +100,7 @@ prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle handle, char const * rv = 0; break; default: - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv; @@ -121,7 +121,7 @@ prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle handle, rv = 0; break; default: - throw SystemException(); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv; diff --git a/Socket/SocketProtocol.cc b/Socket/SocketProtocol.cc index f2fe712..67ed340 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) - throw SystemException("::shutdown(socket_fd)"); + SENF_THROW_SYSTEM_EXCEPTION("::shutdown(socket_fd)"); if (::close(body().fd()) < 0) - throw SystemException("::close(socket_fd)"); + SENF_THROW_SYSTEM_EXCEPTION("::close(socket_fd)"); } prefix_ void senf::SocketProtocol::terminate() diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index f0be324..13668ee 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -46,8 +46,11 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -#define LIBC_CALL(fn, args) if (fn args < 0) throw SystemException(#fn "()") -#define LIBC_CALL_RV(var, fn, args) int var (fn args); if (var < 0) throw SystemException(#fn "()") +#define LIBC_CALL(fn, args) if (fn args < 0) \ + SENF_THROW_SYSTEM_EXCEPTION(#fn "()") + +#define LIBC_CALL_RV(var, fn, args) \ + int var (fn args); if (var < 0) SENF_THROW_SYSTEM_EXCEPTION(#fn "()") /////////////////////////////////////////////////////////////////////////// // senf::Daemon @@ -98,7 +101,7 @@ prefix_ void senf::Daemon::openLog() if (! stdoutLog_.empty()) { fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); if (fd < 0) - throw SystemException() + SENF_THROW_SYSTEM_EXCEPTION("") << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout."; stdout_ = fd; } @@ -107,7 +110,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) - throw SystemException() + SENF_THROW_SYSTEM_EXCEPTION("") << " Could not open \"" << stderrLog_ << "\" for redirecting stderr."; stderr_ = fd; } @@ -156,7 +159,7 @@ prefix_ void senf::Daemon::detach() while (! signaled) { ::sigsuspend(&waitsig); if (errno != EINTR) - throw SystemException("::sigsuspend()"); + SENF_THROW_SYSTEM_EXCEPTION("::sigsuspend()"); } LIBC_CALL( ::sigaction, (SIGUSR1, &oldact, 0) ); @@ -340,17 +343,17 @@ prefix_ bool senf::Daemon::pidfileCreate() { std::ofstream pidf (tempname.c_str()); if (! pidf) - throw SystemException() + SENF_THROW_SYSTEM_EXCEPTION("") << " Could not open pidfile \"" << tempname << "\" for output."; pidf << ::getpid() << std::endl; if (! pidf) - throw SystemException() + SENF_THROW_SYSTEM_EXCEPTION("") << " Could not write to pidfile \"" << tempname << "\"."; } if (::link(tempname.c_str(), pidfile_.c_str()) < 0) { if (errno != EEXIST) - throw SystemException() << linkErrorFormat % pidfile_ % tempname; + SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % pidfile_ % tempname; } else { struct ::stat s; @@ -381,7 +384,7 @@ prefix_ bool senf::Daemon::pidfileCreate() LIBC_CALL( ::unlink, (tempname.c_str() )); if (::link(pidfile_.c_str(), tempname.c_str()) < 0) { if (errno != ENOENT) - throw SystemException() << linkErrorFormat % tempname % pidfile_; + SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % tempname % pidfile_; // Hmm ... the pidfile mysteriously disappeared ... try again. continue; } @@ -444,7 +447,7 @@ prefix_ void senf::detail::DaemonWatcher::pipeClosed(int id) if (sigChld_) childDied(); // does not return if (::kill(childPid_, SIGUSR1) < 0) - if (errno != ESRCH) throw SystemException("::kill()"); + if (errno != ESRCH) SENF_THROW_SYSTEM_EXCEPTION("::kill()"); Scheduler::instance().timeout( Scheduler::instance().eventTime() + ClockService::seconds(1), senf::membind(&DaemonWatcher::childOk, this)); @@ -461,7 +464,7 @@ prefix_ void senf::detail::DaemonWatcher::sigChld() prefix_ void senf::detail::DaemonWatcher::childDied() { int status (0); - if (::waitpid(childPid_,&status,0) < 0) throw SystemException("::waitpid()"); + if (::waitpid(childPid_,&status,0) < 0) SENF_THROW_SYSTEM_EXCEPTION("::waitpid()"); if (WIFSIGNALED(status)) { ::signal(WTERMSIG(status),SIG_DFL); ::kill(::getpid(), WTERMSIG(status)); @@ -512,7 +515,7 @@ prefix_ void senf::detail::DaemonWatcher::Forwarder::readData(Scheduler::EventId while (1) { n = ::read(src_,buf,1024); if (n<0) { - if (errno != EINTR) throw SystemException("::read()"); + if (errno != EINTR) SENF_THROW_SYSTEM_EXCEPTION("::read()"); } else break; } @@ -556,7 +559,7 @@ prefix_ void senf::detail::DaemonWatcher::Forwarder::writeData(Scheduler::EventI int w (::write(target->fd, buf, n)); if (w < 0) { - if (errno != EINTR) throw SystemException("::write()"); + if (errno != EINTR) SENF_THROW_SYSTEM_EXCEPTION("::write()"); return; } target->offset += w; diff --git a/Utils/Exception.cc b/Utils/Exception.cc index e23357f..f94be75 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -47,9 +47,14 @@ prefix_ char const * senf::Exception::what() /////////////////////////////////////////////////////////////////////////// // senf::SystemException -prefix_ void senf::SystemException::init(std::string const & descr, int code) +prefix_ void senf::SystemException::init(std::string const & descr, int code + _SENF_EXC_DEBUG_ARGS_ND) { code_ = code; +# ifdef SENF_DEBUG + if (file && line) + (*this) << "Exception at " << file << ":" << line << "\n"; +# endif (*this) << "[" << errorString() << "]"; if (! descr.empty()) (*this) << " " << descr; } diff --git a/Utils/Exception.cci b/Utils/Exception.cci index f6d5a0a..e7a9c53 100644 --- a/Utils/Exception.cci +++ b/Utils/Exception.cci @@ -35,19 +35,20 @@ prefix_ senf::Exception::Exception(std::string const & description) /////////////////////////////////////////////////////////////////////////// -prefix_ senf::SystemException::SystemException(std::string const & descr) +prefix_ senf::SystemException::SystemException(std::string const & descr _SENF_EXC_DEBUG_ARGS_ND) { - init(descr, errno); + init(descr, errno _SENF_EXC_DEBUG_ARGS_P); } -prefix_ senf::SystemException::SystemException(int code) +prefix_ senf::SystemException::SystemException(int code _SENF_EXC_DEBUG_ARGS_ND) { - init("", code); + init("", code _SENF_EXC_DEBUG_ARGS_P); } -prefix_ senf::SystemException::SystemException(std::string const & descr, int code) +prefix_ senf::SystemException::SystemException(std::string const & descr, int code + _SENF_EXC_DEBUG_ARGS_ND) { - init(descr, code); + init(descr, code _SENF_EXC_DEBUG_ARGS_P); } prefix_ int senf::SystemException::errorNumber() diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 53d962f..eda57d1 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -124,6 +124,15 @@ namespace senf { std::string message_; }; +# ifdef SENF_DEBUG +# define _SENF_EXC_DEBUG_ARGS ,char const * file=0,int line=0 +# define _SENF_EXC_DEBUG_ARGS_ND ,char const *file,int line +# define _SENF_EXC_DEBUG_ARGS_P ,file,line +# else +# define _SENF_EXC_DEBUG_ARGS +# define _SENF_EXC_DEBUG_ARGS_ND +# define _SENF_EXC_DEBUG_ARGS_P +# endif /** \brief Exception handling standard UNIX errors (errno) @@ -143,6 +152,18 @@ namespace senf { throw senf::SystemException(); \endcode + From within SENF (and only there because it depends on the \c SENF_DEBUG symbol), + SystemException should be thrown using wrapper macros which add additional information to + the exception description: + \code + // Standard usage: Take \c errno from environment + SENF_THROW_SYSTEM_EXCEPTION() + << " while opening configuration file: " << filename; + + // You may however explicitly specify the errno value + throw senf::SystemException("::open()", ENOFILE SENF_EXC_DEBUGINFO) + \endcode + \ingroup exception */ class SystemException : public Exception @@ -152,9 +173,9 @@ namespace senf { ///\name Structors and default members ///@{ - explicit SystemException(std::string const & descr = ""); - explicit SystemException(int code); - SystemException(std::string const & descr, int code); + explicit SystemException(std::string const & descr = "" _SENF_EXC_DEBUG_ARGS); + explicit SystemException(int code _SENF_EXC_DEBUG_ARGS); + SystemException(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS); virtual ~SystemException() throw(); @@ -171,12 +192,20 @@ namespace senf { private: - void init(std::string const & descr, int code); + void init(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS_ND); int code_; std::string what_; }; +# ifdef SENF_DEBUG +# define SENF_EXC_DEBUGINFO ,__FILE__,__LINE__ +# else +# define SENF_EXC_DEBUGINFO +# endif + +# define SENF_THROW_SYSTEM_EXCEPTION(desc) throw SystemException(desc SENF_EXC_DEBUGINFO) + } ///////////////////////////////hh.e////////////////////////////////////////