Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66005 - in trunk: boost/asio/detail libs/asio/test
From: chris_at_[hidden]
Date: 2010-10-16 02:27:50


Author: chris_kohlhoff
Date: 2010-10-16 02:27:45 EDT (Sat, 16 Oct 2010)
New Revision: 66005
URL: http://svn.boost.org/trac/boost/changeset/66005

Log:
Fix a const-correctness issue that prevents valid uses of has_service<> from compiling. Refs #4638.

Text files modified:
   trunk/boost/asio/detail/service_registry.hpp | 5 +-
   trunk/libs/asio/test/io_service.cpp | 71 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 74 insertions(+), 2 deletions(-)

Modified: trunk/boost/asio/detail/service_registry.hpp
==============================================================================
--- trunk/boost/asio/detail/service_registry.hpp (original)
+++ trunk/boost/asio/detail/service_registry.hpp 2010-10-16 02:27:45 EDT (Sat, 16 Oct 2010)
@@ -75,13 +75,14 @@
 
 private:
   // Initialise a service's key based on its id.
- BOOST_ASIO_DECL void init_key(boost::asio::io_service::service::key& key,
+ BOOST_ASIO_DECL static void init_key(
+ boost::asio::io_service::service::key& key,
       const boost::asio::io_service::id& id);
 
 #if !defined(BOOST_ASIO_NO_TYPEID)
   // Initialise a service's key based on its id.
   template <typename Service>
- void init_key(boost::asio::io_service::service::key& key,
+ static void init_key(boost::asio::io_service::service::key& key,
       const boost::asio::detail::service_id<Service>& /*id*/);
 #endif // !defined(BOOST_ASIO_NO_TYPEID)
 

Modified: trunk/libs/asio/test/io_service.cpp
==============================================================================
--- trunk/libs/asio/test/io_service.cpp (original)
+++ trunk/libs/asio/test/io_service.cpp 2010-10-16 02:27:45 EDT (Sat, 16 Oct 2010)
@@ -234,9 +234,80 @@
   BOOST_CHECK(exception_count == 2);
 }
 
+class test_service : public boost::asio::io_service::service
+{
+public:
+ static boost::asio::io_service::id id;
+ test_service(boost::asio::io_service& s)
+ : boost::asio::io_service::service(s) {}
+private:
+ virtual void shutdown_service() {}
+};
+
+boost::asio::io_service::id test_service::id;
+
+void io_service_service_test()
+{
+ boost::asio::io_service ios1;
+ boost::asio::io_service ios2;
+ boost::asio::io_service ios3;
+
+ // Implicit service registration.
+
+ boost::asio::use_service<test_service>(ios1);
+
+ BOOST_CHECK(boost::asio::has_service<test_service>(ios1));
+
+ test_service* svc1 = new test_service(ios1);
+ try
+ {
+ boost::asio::add_service(ios1, svc1);
+ BOOST_ERROR("add_service did not throw");
+ }
+ catch (boost::asio::service_already_exists&)
+ {
+ }
+ delete svc1;
+
+ // Explicit service registration.
+
+ test_service* svc2 = new test_service(ios2);
+ boost::asio::add_service(ios2, svc2);
+
+ BOOST_CHECK(boost::asio::has_service<test_service>(ios2));
+ BOOST_CHECK(&boost::asio::use_service<test_service>(ios2) == svc2);
+
+ test_service* svc3 = new test_service(ios2);
+ try
+ {
+ boost::asio::add_service(ios2, svc3);
+ BOOST_ERROR("add_service did not throw");
+ }
+ catch (boost::asio::service_already_exists&)
+ {
+ }
+ delete svc3;
+
+ // Explicit registration with invalid owner.
+
+ test_service* svc4 = new test_service(ios2);
+ try
+ {
+ boost::asio::add_service(ios3, svc4);
+ BOOST_ERROR("add_service did not throw");
+ }
+ catch (boost::asio::invalid_service_owner&)
+ {
+ }
+ delete svc4;
+
+ BOOST_CHECK(!boost::asio::has_service<test_service>(ios3));
+}
+
 test_suite* init_unit_test_suite(int, char*[])
 {
   test_suite* test = BOOST_TEST_SUITE("io_service");
   test->add(BOOST_TEST_CASE(&io_service_test));
+ test->add(BOOST_TEST_CASE(&io_service_service_test));
   return test;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk