From: g0dil Date: Thu, 2 Apr 2009 12:40:58 +0000 (+0000) Subject: PPI: Add TargetDgramWriter X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=09b4d2c4934a5ea35d208cd22573e0e877ad54c8;p=senf.git PPI: Add TargetDgramWriter Socket: Add up(), down() and isUp() members to NetdeviceController Utils/Daemon: Fix dup() bug Utils/Daemon: Dump registered scheduler events on fork() WARNING git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1178 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/SocketSink.cti b/PPI/SocketSink.cti index b7482eb..07dba5b 100644 --- a/PPI/SocketSink.cti +++ b/PPI/SocketSink.cti @@ -31,6 +31,42 @@ ///////////////////////////////cti.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// +// senf::ppi::TargetDgramWriter + +template +prefix_ senf::ppi::TargetDgramWriter::TargetDgramWriter() +{} + +template +prefix_ senf::ppi::TargetDgramWriter:: +TargetDgramWriter(typename Handle::Address const & target) +: target_ (target) +{} + +template +prefix_ typename senf::ppi::TargetDgramWriter::Handle::Address +senf::ppi::TargetDgramWriter::target() + const +{ + return target_; +} + +template +prefix_ void +senf::ppi::TargetDgramWriter::target(typename Handle::Address const & target) +{ + target_ = target; +} + +template +prefix_ void senf::ppi::TargetDgramWriter::operator()(Handle handle, + Packet const & packet) +{ + if (target_) + handle.writeto(target_, packet.data()); +} + +/////////////////////////////////////////////////////////////////////////// // senf::ppi::module::ActiveSocketSink template diff --git a/PPI/SocketSink.hh b/PPI/SocketSink.hh index 83a1d5f..e87b66f 100644 --- a/PPI/SocketSink.hh +++ b/PPI/SocketSink.hh @@ -65,6 +65,24 @@ namespace ppi { \param[in] packet Packet to write */ }; + template + class TargetDgramWriter + { + public: + typedef HandleType Handle; + + TargetDgramWriter(); + TargetDgramWriter(typename Handle::Address const & target); + + typename Handle::Address target() const; + void target(typename Handle::Address const & target); + + void operator()(Handle handle, Packet const & packet); + + private: + typename Handle::Address target_; + }; + class IPv4SourceForcingDgramWriter : ConnectedDgramWriter { public: diff --git a/Scheduler/EventManager.cc b/Scheduler/EventManager.cc index 30ac6d2..d267a1e 100644 --- a/Scheduler/EventManager.cc +++ b/Scheduler/EventManager.cc @@ -39,7 +39,7 @@ prefix_ senf::scheduler::detail::EventManager::EventManager() { #ifndef SENF_DISABLE_CONSOLE - consoleDir_().add("events", senf::membind(&EventManager::consoleEvents, this)) + consoleDir_().add("events", senf::membind(&EventManager::listEvents, this)) .doc("List all scheduler events sorted by priority\n" "\n" "Columns:\n" @@ -61,7 +61,7 @@ prefix_ senf::scheduler::detail::EventManager::EventManager() #endif } -prefix_ void senf::scheduler::detail::EventManager::consoleEvents(std::ostream & os) +prefix_ void senf::scheduler::detail::EventManager::listEvents(std::ostream & os) { // On an 80 column display, this wraps nicely directly before the INFO column boost::format fmt ("%s %-55.55s 0x%08x %8d %s %s\n"); diff --git a/Scheduler/EventManager.hh b/Scheduler/EventManager.hh index 7586556..099ebae 100644 --- a/Scheduler/EventManager.hh +++ b/Scheduler/EventManager.hh @@ -105,6 +105,8 @@ namespace detail { iterator begin() const; iterator end() const; + void listEvents(std::ostream & os); + protected: private: @@ -115,8 +117,6 @@ namespace detail { friend class singleton; #ifndef SENF_DISABLE_CONSOLE - void consoleEvents(std::ostream & os); - console::LazyDirectory consoleDir_; #endif }; diff --git a/Socket/NetdeviceController.cc b/Socket/NetdeviceController.cc index 345679b..b514904 100644 --- a/Socket/NetdeviceController.cc +++ b/Socket/NetdeviceController.cc @@ -136,6 +136,33 @@ prefix_ void senf::NetdeviceController::promisc(bool mode) doIoctl( ifr, SIOCSIFFLAGS); } +prefix_ bool senf::NetdeviceController::isUp() + const +{ + struct ifreq ifr; + ifrName(ifr); + doIoctl(ifr, SIOCGIFFLAGS); + return ifr.ifr_flags & IFF_UP; +} + +prefix_ void senf::NetdeviceController::up() +{ + struct ifreq ifr; + ifrName(ifr); + doIoctl(ifr, SIOCGIFFLAGS); + ifr.ifr_flags |= IFF_UP; + doIoctl(ifr, SIOCSIFFLAGS); +} + +prefix_ void senf::NetdeviceController::down() +{ + struct ifreq ifr; + ifrName(ifr); + doIoctl(ifr, SIOCGIFFLAGS); + ifr.ifr_flags &= ~IFF_UP; + doIoctl(ifr, SIOCSIFFLAGS); +} + prefix_ int senf::NetdeviceController::interfaceIndex() const { diff --git a/Socket/NetdeviceController.hh b/Socket/NetdeviceController.hh index db7c5cf..ed74c18 100644 --- a/Socket/NetdeviceController.hh +++ b/Socket/NetdeviceController.hh @@ -84,7 +84,11 @@ namespace senf { bool promisc() const; ///< return \c true if interface is in promiscuous mode void promisc(bool mode); ///< enable/disable promiscuous mode of the interface /**< Note, that this is a privileged operation. */ - + + bool isUp() const; ///< return \c true if interface is up + void up(); ///< ifconfig up interface + void down(); ///< ifconfig down interface + private: void openSocket(); void doIoctl(ifreq& ifr, int request) const; diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index 8cbf98f..1b6e8ae 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -132,17 +132,19 @@ prefix_ void senf::Daemon::openLog() << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout."; stdout_ = fd; } - if (stderrLog_ == stdoutLog_) { - stderr_ = ::dup(fd); - if (stderr_ < 0) - SENF_THROW_SYSTEM_EXCEPTION("::dup()"); - } - else if (! stderrLog_.empty()) { - fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); - if (fd < 0) - SENF_THROW_SYSTEM_EXCEPTION("") - << " Could not open \"" << stderrLog_ << "\" for redirecting stderr."; - stderr_ = fd; + if (! stderrLog_.empty()) { + if (stderrLog_ == stdoutLog_) { + stderr_ = ::dup(fd); + if (stderr_ < 0) + SENF_THROW_SYSTEM_EXCEPTION("::dup()"); + } + else { + fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); + if (fd < 0) + SENF_THROW_SYSTEM_EXCEPTION("") + << " Could not open \"" << stderrLog_ << "\" for redirecting stderr."; + stderr_ = fd; + } } } @@ -369,14 +371,17 @@ prefix_ void senf::Daemon::fork() LIBC_CALL( ::sigaddset, (&cldsig, SIGCHLD) ); LIBC_CALL( ::sigprocmask, (SIG_BLOCK, &cldsig, &oldsig) ); - if (! senf::scheduler::empty() ) + if (! senf::scheduler::empty() ) { std::cerr << "\n" "*** WARNING ***\n" "Scheduler not empty before fork(). THIS MUST NOT HAPPEN.\n" - "The scheduler will be reinitialized by the fork() and lose all registrations.\n" - "*** WARNING ***\n" + "The scheduler will be reinitialized by the fork() and lose all registrations.\n\n"; + senf::scheduler::detail::EventManager::instance().listEvents(std::cerr); + std::cerr << + "\n*** WARNING ***\n" "\n"; + } LIBC_CALL_RV( pid, ::fork, () );