From: tho Date: Fri, 23 Sep 2011 12:52:06 +0000 (+0000) Subject: Packets: static assertion for duplicate tlv parser registration X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=731487d5f44eaa8c07a21de1dfa00cea2150c80e;p=senf.git Packets: static assertion for duplicate tlv parser registration git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1812 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/GenericTLV.ct b/senf/Packets/GenericTLV.ct index 1fa98e3..cb71af7 100644 --- a/senf/Packets/GenericTLV.ct +++ b/senf/Packets/GenericTLV.ct @@ -102,9 +102,9 @@ template prefix_ void senf::GenericTLVParserRegistry::registerParser() { Keytype key (Parser::typeId+0); - typename Map::iterator i (map_.find( key )); - if (i == map_.end() ) - map_.insert(key, new detail::GenericTLVParserRegistry_Entry() ); + SENF_ASSERT_EXPRESSION( + map_.insert( key, new detail::GenericTLVParserRegistry_Entry()).second == true, + "Duplicate TLV registration"); } // Wow ... this is stupid .. Boost 1.33 ptr_map API is broken ... diff --git a/senf/Packets/PacketRegistry.ct b/senf/Packets/PacketRegistry.ct index 6c594b9..81e9983 100644 --- a/senf/Packets/PacketRegistry.ct +++ b/senf/Packets/PacketRegistry.ct @@ -106,7 +106,7 @@ template template prefix_ void senf::detail::PacketRegistryImpl::unregisterPacket() { - registry_.template get().erase(typeid(PacketType)); + registryByType_.erase(typeid(PacketType)); } template @@ -133,10 +133,8 @@ template prefix_ boost::optional::key_t> senf::detail::PacketRegistryImpl::key(senf::TypeIdValue const & type, bool) { - typedef typename Registry::template index::type TypeIndex; - TypeIndex const & typeIndex (registry_.template get()); - typename TypeIndex::const_iterator i (typeIndex.find(type.id())); - if (i == typeIndex.end()) + typename RegistryByType::const_iterator i (registryByType_.find(type.id())); + if (i == registryByType_.end()) return boost::optional(); return (*i)->key; } @@ -144,6 +142,7 @@ senf::detail::PacketRegistryImpl::key(senf::TypeIdValue const & type, b template prefix_ typename senf::detail::PacketRegistryImpl::Entry const & senf::detail::PacketRegistryImpl::lookup(key_t key) + const { Entry const * e (lookup(key, true)); if (!e) @@ -154,11 +153,10 @@ senf::detail::PacketRegistryImpl::lookup(key_t key) template prefix_ typename senf::detail::PacketRegistryImpl::Entry const * senf::detail::PacketRegistryImpl::lookup(key_t key, bool) + const { - typedef typename Registry::template index::type KeyIndex; - KeyIndex const & keyIndex (registry_.template get()); - typename KeyIndex::const_iterator i (keyIndex.lower_bound(key)); - if (i == keyIndex.end() || (*i)->key != key) + typename RegistryByKey::const_iterator i (registryByKey_.lower_bound(key)); + if (i == registryByKey_.end() || (*i)->key != key) return 0; return i->get(); } @@ -174,10 +172,7 @@ template prefix_ void senf::detail::PacketRegistryImpl::v_dump(std::ostream & os) const { - typedef typename Registry::template index::type KeyIndex; - KeyIndex const & keyIndex (registry_.template get()); - for (typename KeyIndex::iterator i (keyIndex.begin()), i_end (keyIndex.end()); - i != i_end; ++i) { + for (typename RegistryByKey::const_iterator i (registryByKey_.begin()), i_end (registryByKey_.end()); i != i_end; ++i) { std::string n ((*i)->name()); senf::detail::DumpKey::dump((*i)->key, os); os << ' ' << std::setw(6) << (*i)->priority << ' ' << n.substr(21,n.size()-22) << '\n'; diff --git a/senf/Packets/PacketRegistry.cti b/senf/Packets/PacketRegistry.cti index df4df66..d999b0e 100644 --- a/senf/Packets/PacketRegistry.cti +++ b/senf/Packets/PacketRegistry.cti @@ -152,6 +152,8 @@ senf::PacketRegistry::registry() template prefix_ senf::detail::PacketRegistryImpl::PacketRegistryImpl(std::string const & name) + : registryByKey_( registry_.template get()), + registryByType_( registry_.template get()) { registries()[name] = this; } diff --git a/senf/Packets/PacketRegistry.ih b/senf/Packets/PacketRegistry.ih index adf2f28..c5d3ac4 100644 --- a/senf/Packets/PacketRegistry.ih +++ b/senf/Packets/PacketRegistry.ih @@ -125,6 +125,8 @@ namespace detail { {}; typedef boost::multi_index_container Registry; + typedef typename Registry::template index::type RegistryByKey; + typedef typename Registry::template index::type RegistryByType; template struct EntryImpl : public Entry @@ -161,8 +163,8 @@ namespace detail { key_t key(senf::TypeIdValue const & type); boost::optional key(senf::TypeIdValue const & type, bool); - Entry const & lookup(key_t key); - Entry const * lookup(key_t key, bool); + Entry const & lookup(key_t key) const; + Entry const * lookup(key_t key, bool) const; iterator begin() const; iterator end() const; @@ -175,6 +177,8 @@ namespace detail { virtual void v_clear(); Registry registry_; + RegistryByKey & registryByKey_; + RegistryByType & registryByType_; }; template ::is_integer> diff --git a/senf/Socket/ReadWritePolicy.cc b/senf/Socket/ReadWritePolicy.cc index eb04cf7..a573e5d 100644 --- a/senf/Socket/ReadWritePolicy.cc +++ b/senf/Socket/ReadWritePolicy.cc @@ -133,9 +133,9 @@ prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle & handle, rv = 0; break; default: - std::stringstream a, b; + std::stringstream a, b; senf::hexdump( (char*) addr , ((char*) addr) + len , a); - senf::hexdump( (char*) buffer , ((char*) buffer) + size , b); + senf::hexdump( (char*) buffer , ((char*) buffer) + size , b); SENF_THROW_SYSTEM_EXCEPTION("::sendto(" + b.str() + ") to " + a.str()); } } while (rv<0); diff --git a/senf/Utils/Console/Server.cc b/senf/Utils/Console/Server.cc index 6bb4aae..aef6bc5 100644 --- a/senf/Utils/Console/Server.cc +++ b/senf/Utils/Console/Server.cc @@ -345,7 +345,7 @@ prefix_ senf::console::Client::Client(Server & server, ClientHandle handle) false), name_ (server.name()), reader_ (), mode_ (server.mode()) { - handle_.facet().nodelay(); + handle_.facet().nodelay(true); handle_.blocking(false); executor_.chroot(root()); switch (mode_) {