Update of /cvsroot/boost/boost/boost/asio/detail
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6071/boost/asio/detail
Modified Files:
bind_handler.hpp reactive_socket_service.hpp
strand_service.hpp task_io_service.hpp win_iocp_io_service.hpp
win_iocp_socket_service.hpp wrapped_handler.hpp
Added Files:
handler_dispatch_helpers.hpp
Log Message:
Change strand implementation so that dispatch will execute a handler
immediately if called from within the strand.
Add hook function for customising handler dispatch.
Need to use reinterpret_cast when testing for enable_connection_aborted
socket option, to allow non-int socket options to compile correctly.
--- NEW FILE: handler_dispatch_helpers.hpp ---
//
// handler_dispatch_helpers.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2006 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_DETAIL_HANDLER_DISPATCH_HELPERS_HPP
#define BOOST_ASIO_DETAIL_HANDLER_DISPATCH_HELPERS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/push_options.hpp>
#include <boost/asio/detail/push_options.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/handler_dispatch_hook.hpp>
// Calls to asio_handler_dispatch must be made from a namespace that does not
// contain overloads of this function. The boost_asio_handler_dispatch_helpers
// namespace is defined here for that purpose.
namespace boost_asio_handler_dispatch_helpers {
template <typename Handler, typename Context>
inline void dispatch_handler(const Handler& handler, Context* context)
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
Handler tmp(handler);
tmp();
#else
using namespace boost::asio;
asio_handler_dispatch(handler, context);
#endif
}
} // namespace boost_asio_handler_dispatch_helpers
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_DETAIL_HANDLER_DISPATCH_HELPERS_HPP
Index: bind_handler.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/bind_handler.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- bind_handler.hpp 14 Jun 2006 22:26:30 -0000 1.1
+++ bind_handler.hpp 5 Jul 2006 05:48:09 -0000 1.2
@@ -1,6 +1,6 @@
//
-// bind.hpp
-// ~~~~~~~~
+// bind_handler.hpp
+// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2006 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -8,8 +8,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_DETAIL_BIND_HPP
-#define BOOST_ASIO_DETAIL_BIND_HPP
+#ifndef BOOST_ASIO_DETAIL_BIND_HANDLER_HPP
+#define BOOST_ASIO_DETAIL_BIND_HANDLER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
@@ -18,6 +18,7 @@
#include <boost/asio/detail/push_options.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_dispatch_helpers.hpp>
namespace boost {
namespace asio {
@@ -27,7 +28,7 @@
class binder1
{
public:
- binder1(Handler handler, Arg1 arg1)
+ binder1(const Handler& handler, const Arg1& arg1)
: handler_(handler),
arg1_(arg1)
{
@@ -43,27 +44,38 @@
handler_(arg1_);
}
- friend void* asio_handler_allocate(std::size_t size,
- binder1<Handler, Arg1>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, &this_handler->handler_);
- }
-
- friend void asio_handler_deallocate(void* pointer, std::size_t size,
- binder1<Handler, Arg1>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, &this_handler->handler_);
- }
-
-private:
+//private:
Handler handler_;
Arg1 arg1_;
};
template <typename Handler, typename Arg1>
-binder1<Handler, Arg1> bind_handler(Handler handler, Arg1 arg1)
+inline void* asio_handler_allocate(std::size_t size,
+ binder1<Handler, Arg1>* this_handler)
+{
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1>
+inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ binder1<Handler, Arg1>* this_handler)
+{
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, &this_handler->handler_);
+}
+
+template <typename Handler_To_Dispatch, typename Handler, typename Arg1>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ binder1<Handler, Arg1>* this_handler)
+{
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ handler, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1>
+inline binder1<Handler, Arg1> bind_handler(const Handler& handler,
+ const Arg1& arg1)
{
return binder1<Handler, Arg1>(handler, arg1);
}
@@ -72,7 +84,7 @@
class binder2
{
public:
- binder2(Handler handler, Arg1 arg1, Arg2 arg2)
+ binder2(const Handler& handler, const Arg1& arg1, const Arg2& arg2)
: handler_(handler),
arg1_(arg1),
arg2_(arg2)
@@ -89,29 +101,40 @@
handler_(arg1_, arg2_);
}
- friend void* asio_handler_allocate(std::size_t size,
- binder2<Handler, Arg1, Arg2>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, &this_handler->handler_);
- }
-
- friend void asio_handler_deallocate(void* pointer, std::size_t size,
- binder2<Handler, Arg1, Arg2>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, &this_handler->handler_);
- }
-
-private:
+//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
};
template <typename Handler, typename Arg1, typename Arg2>
-binder2<Handler, Arg1, Arg2> bind_handler(Handler handler, Arg1 arg1,
- Arg2 arg2)
+inline void* asio_handler_allocate(std::size_t size,
+ binder2<Handler, Arg1, Arg2>* this_handler)
+{
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2>
+inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ binder2<Handler, Arg1, Arg2>* this_handler)
+{
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, &this_handler->handler_);
+}
+
+template <typename Handler_To_Dispatch, typename Handler, typename Arg1,
+ typename Arg2>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ binder2<Handler, Arg1, Arg2>* this_handler)
+{
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ handler, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2>
+inline binder2<Handler, Arg1, Arg2> bind_handler(const Handler& handler,
+ const Arg1& arg1, const Arg2& arg2)
{
return binder2<Handler, Arg1, Arg2>(handler, arg1, arg2);
}
@@ -120,7 +143,8 @@
class binder3
{
public:
- binder3(Handler handler, Arg1 arg1, Arg2 arg2, Arg3 arg3)
+ binder3(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
+ const Arg3& arg3)
: handler_(handler),
arg1_(arg1),
arg2_(arg2),
@@ -138,21 +162,7 @@
handler_(arg1_, arg2_, arg3_);
}
- friend void* asio_handler_allocate(std::size_t size,
- binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, &this_handler->handler_);
- }
-
- friend void asio_handler_deallocate(void* pointer, std::size_t size,
- binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, &this_handler->handler_);
- }
-
-private:
+//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
@@ -160,8 +170,33 @@
};
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
-binder3<Handler, Arg1, Arg2, Arg3> bind_handler(Handler handler, Arg1 arg1,
- Arg2 arg2, Arg3 arg3)
+inline void* asio_handler_allocate(std::size_t size,
+ binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
+{
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
+inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
+{
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, &this_handler->handler_);
+}
+
+template <typename Handler_To_Dispatch, typename Handler, typename Arg1,
+ typename Arg2, typename Arg3>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
+{
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ handler, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
+inline binder3<Handler, Arg1, Arg2, Arg3> bind_handler(const Handler& handler,
+ const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
{
return binder3<Handler, Arg1, Arg2, Arg3>(handler, arg1, arg2, arg3);
}
@@ -171,7 +206,8 @@
class binder4
{
public:
- binder4(Handler handler, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
+ binder4(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
+ const Arg3& arg3, const Arg4& arg4)
: handler_(handler),
arg1_(arg1),
arg2_(arg2),
@@ -190,21 +226,7 @@
handler_(arg1_, arg2_, arg3_, arg4_);
}
- friend void* asio_handler_allocate(std::size_t size,
- binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, &this_handler->handler_);
- }
-
- friend void asio_handler_deallocate(void* pointer, std::size_t size,
- binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, &this_handler->handler_);
- }
-
-private:
+//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
@@ -214,8 +236,36 @@
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
typename Arg4>
-binder4<Handler, Arg1, Arg2, Arg3, Arg4> bind_handler(Handler handler,
- Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
+inline void* asio_handler_allocate(std::size_t size,
+ binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
+{
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4>
+inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
+{
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, &this_handler->handler_);
+}
+
+template <typename Handler_To_Dispatch, typename Handler, typename Arg1,
+ typename Arg2, typename Arg3, typename Arg4>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
+{
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ handler, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4>
+inline binder4<Handler, Arg1, Arg2, Arg3, Arg4> bind_handler(
+ const Handler& handler, const Arg1& arg1, const Arg2& arg2,
+ const Arg3& arg3, const Arg4& arg4)
{
return binder4<Handler, Arg1, Arg2, Arg3, Arg4>(handler, arg1, arg2, arg3,
arg4);
@@ -226,8 +276,8 @@
class binder5
{
public:
- binder5(Handler handler, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,
- Arg5 arg5)
+ binder5(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
+ const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
: handler_(handler),
arg1_(arg1),
arg2_(arg2),
@@ -247,21 +297,7 @@
handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
}
- friend void* asio_handler_allocate(std::size_t size,
- binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, &this_handler->handler_);
- }
-
- friend void asio_handler_deallocate(void* pointer, std::size_t size,
- binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, &this_handler->handler_);
- }
-
-private:
+//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
@@ -272,8 +308,36 @@
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5>
-binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5> bind_handler(Handler handler,
- Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
+inline void* asio_handler_allocate(std::size_t size,
+ binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
+{
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5>
+inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
+{
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, &this_handler->handler_);
+}
+
+template <typename Handler_To_Dispatch, typename Handler, typename Arg1,
+ typename Arg2, typename Arg3, typename Arg4, typename Arg5>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
+{
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ handler, &this_handler->handler_);
+}
+
+template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5>
+inline binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5> bind_handler(
+ const Handler& handler, const Arg1& arg1, const Arg2& arg2,
+ const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
{
return binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>(handler, arg1, arg2,
arg3, arg4, arg5);
@@ -285,4 +349,4 @@
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_DETAIL_BIND_HPP
+#endif // BOOST_ASIO_DETAIL_BIND_HANDLER_HPP
Index: reactive_socket_service.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/reactive_socket_service.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- reactive_socket_service.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ reactive_socket_service.hpp 5 Jul 2006 05:48:09 -0000 1.2
@@ -233,7 +233,7 @@
}
else
{
- if (*static_cast<const int*>(option.data(impl.protocol_)))
+ if (*reinterpret_cast<const int*>(option.data(impl.protocol_)))
impl.flags_ |= implementation_type::enable_connection_aborted;
else
impl.flags_ &= ~implementation_type::enable_connection_aborted;
@@ -265,7 +265,7 @@
}
else
{
- int* target = static_cast<int*>(option.data(impl.protocol_));
+ int* target = reinterpret_cast<int*>(option.data(impl.protocol_));
if (impl.flags_ & implementation_type::enable_connection_aborted)
*target = 1;
else
Index: strand_service.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/strand_service.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- strand_service.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ strand_service.hpp 5 Jul 2006 05:48:09 -0000 1.2
@@ -24,10 +24,11 @@
#include <boost/asio/io_service.hpp>
#include <boost/asio/detail/bind_handler.hpp>
+#include <boost/asio/detail/call_stack.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_dispatch_helpers.hpp>
#include <boost/asio/detail/mutex.hpp>
#include <boost/asio/detail/noncopyable.hpp>
-#include <boost/asio/detail/strand_service.hpp>
namespace boost {
namespace asio {
@@ -143,6 +144,13 @@
return impl_.handler_storage_.address();
}
+ template <typename Handler_To_Dispatch>
+ friend void asio_handler_dispatch(Handler_To_Dispatch handler,
+ invoke_current_handler*)
+ {
+ handler();
+ }
+
private:
strand_service& service_impl_;
implementation_type& impl_;
@@ -227,8 +235,11 @@
// Free the memory associated with the handler.
ptr.reset();
+ // Indicate that this strand is executing on the current thread.
+ call_stack<implementation_type>::context ctx(&impl);
+
// Make the upcall.
- handler();
+ boost_asio_handler_dispatch_helpers::dispatch_handler(handler, &handler);
}
static void do_destroy(handler_base* base)
@@ -336,38 +347,45 @@
template <typename Handler>
void dispatch(implementation_type& impl, Handler handler)
{
- boost::asio::detail::mutex::scoped_lock lock(impl.mutex_);
-
- // Allocate and construct an object to wrap the handler.
- typedef handler_wrapper<Handler> value_type;
- typedef handler_alloc_traits<Handler, value_type> alloc_traits;
- raw_handler_ptr<alloc_traits> raw_ptr(handler);
- handler_ptr<alloc_traits> ptr(raw_ptr, handler);
-
- if (impl.current_handler_ == 0)
+ if (call_stack<implementation_type>::contains(&impl))
{
- // This handler now has the lock, so can be dispatched immediately.
- impl.current_handler_ = ptr.get();
- lock.unlock();
- owner().dispatch(invoke_current_handler(*this, impl));
- ptr.release();
+ boost_asio_handler_dispatch_helpers::dispatch_handler(handler, &handler);
}
else
{
- // Another handler already holds the lock, so this handler must join the
- // list of waiters. The handler will be posted automatically when its
turn
- // comes.
- if (impl.last_waiter_)
+ boost::asio::detail::mutex::scoped_lock lock(impl.mutex_);
+
+ // Allocate and construct an object to wrap the handler.
+ typedef handler_wrapper<Handler> value_type;
+ typedef handler_alloc_traits<Handler, value_type> alloc_traits;
+ raw_handler_ptr<alloc_traits> raw_ptr(handler);
+ handler_ptr<alloc_traits> ptr(raw_ptr, handler);
+
+ if (impl.current_handler_ == 0)
{
- impl.last_waiter_->next_ = ptr.get();
- impl.last_waiter_ = impl.last_waiter_->next_;
+ // This handler now has the lock, so can be dispatched immediately.
+ impl.current_handler_ = ptr.get();
+ lock.unlock();
+ owner().dispatch(invoke_current_handler(*this, impl));
+ ptr.release();
}
else
{
- impl.first_waiter_ = ptr.get();
- impl.last_waiter_ = ptr.get();
+ // Another handler already holds the lock, so this handler must join
+ // the list of waiters. The handler will be posted automatically when
+ // its turn comes.
+ if (impl.last_waiter_)
+ {
+ impl.last_waiter_->next_ = ptr.get();
+ impl.last_waiter_ = impl.last_waiter_->next_;
+ }
+ else
+ {
+ impl.first_waiter_ = ptr.get();
+ impl.last_waiter_ = ptr.get();
+ }
+ ptr.release();
}
- ptr.release();
}
}
Index: task_io_service.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/task_io_service.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- task_io_service.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ task_io_service.hpp 5 Jul 2006 05:48:09 -0000 1.2
@@ -21,6 +21,7 @@
#include <boost/asio/detail/call_stack.hpp>
#include <boost/asio/detail/event.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_dispatch_helpers.hpp>
#include <boost/asio/detail/mutex.hpp>
#include <boost/asio/detail/task_io_service_fwd.hpp>
@@ -181,7 +182,7 @@
void dispatch(Handler handler)
{
if (call_stack<task_io_service>::contains(this))
- handler();
+ boost_asio_handler_dispatch_helpers::dispatch_handler(handler, &handler);
else
post(handler);
}
@@ -331,7 +332,7 @@
ptr.reset();
// Make the upcall.
- handler();
+ boost_asio_handler_dispatch_helpers::dispatch_handler(handler, &handler);
}
static void do_destroy(handler_base* base)
Index: win_iocp_io_service.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/win_iocp_io_service.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- win_iocp_io_service.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ win_iocp_io_service.hpp 5 Jul 2006 05:48:10 -0000 1.2
@@ -29,6 +29,7 @@
#include <boost/asio/system_exception.hpp>
#include <boost/asio/detail/call_stack.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_dispatch_helpers.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/win_iocp_operation.hpp>
@@ -238,7 +239,7 @@
ptr.reset();
// Make the upcall.
- handler();
+ boost_asio_handler_dispatch_helpers::dispatch_handler(handler, &handler);
}
static void destroy_impl(operation* op)
@@ -259,7 +260,7 @@
void dispatch(Handler handler)
{
if (call_stack<win_iocp_io_service>::contains(this))
- handler();
+ boost_asio_handler_dispatch_helpers::dispatch_handler(handler, &handler);
else
post(handler);
}
Index: win_iocp_socket_service.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/win_iocp_socket_service.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- win_iocp_socket_service.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ win_iocp_socket_service.hpp 5 Jul 2006 05:48:10 -0000 1.2
@@ -34,6 +34,7 @@
#include <boost/asio/socket_base.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_dispatch_helpers.hpp>
#include <boost/asio/detail/mutex.hpp>
#include <boost/asio/detail/select_reactor.hpp>
#include <boost/asio/detail/socket_holder.hpp>
@@ -289,7 +290,7 @@
}
else
{
- if (*static_cast<const int*>(option.data(impl.protocol_)))
+ if (*reinterpret_cast<const int*>(option.data(impl.protocol_)))
impl.flags_ |= implementation_type::enable_connection_aborted;
else
impl.flags_ &= ~implementation_type::enable_connection_aborted;
@@ -321,7 +322,7 @@
}
else
{
- int* target = static_cast<int*>(option.data(impl.protocol_));
+ int* target = reinterpret_cast<int*>(option.data(impl.protocol_));
if (impl.flags_ & implementation_type::enable_connection_aborted)
*target = 1;
else
@@ -477,7 +478,8 @@
// Call the handler.
boost::asio::error error(last_error);
- handler(error, bytes_transferred);
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ detail::bind_handler(handler, error, bytes_transferred), &handler);
}
static void destroy_impl(operation* op)
@@ -610,7 +612,8 @@
// Call the handler.
boost::asio::error error(last_error);
- handler(error, bytes_transferred);
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ detail::bind_handler(handler, error, bytes_transferred), &handler);
}
static void destroy_impl(operation* op)
@@ -764,7 +767,8 @@
// Call the handler.
boost::asio::error error(last_error);
- handler(error, bytes_transferred);
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ detail::bind_handler(handler, error, bytes_transferred), &handler);
}
static void destroy_impl(operation* op)
@@ -920,7 +924,8 @@
// Call the handler.
boost::asio::error error(last_error);
- handler(error, bytes_transferred);
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ detail::bind_handler(handler, error, bytes_transferred), &handler);
}
static void destroy_impl(operation* op)
@@ -1224,7 +1229,8 @@
// Call the handler.
boost::asio::error error(last_error);
- handler(error);
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ detail::bind_handler(handler, error), &handler);
}
static void destroy_impl(operation* op)
@@ -1489,7 +1495,8 @@
// Call the handler.
boost::asio::error error(last_error);
- handler(error);
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ detail::bind_handler(handler, error), &handler);
}
static void destroy_impl(operation* op)
Index: wrapped_handler.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/detail/wrapped_handler.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- wrapped_handler.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ wrapped_handler.hpp 5 Jul 2006 05:48:10 -0000 1.2
@@ -19,6 +19,7 @@
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_dispatch_helpers.hpp>
namespace boost {
namespace asio {
@@ -47,50 +48,52 @@
}
template <typename Arg1>
- void operator()(Arg1 arg1)
+ void operator()(const Arg1& arg1)
{
dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
}
template <typename Arg1>
- void operator()(Arg1 arg1) const
+ void operator()(const Arg1& arg1) const
{
dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
}
template <typename Arg1, typename Arg2>
- void operator()(Arg1 arg1, Arg2 arg2)
+ void operator()(const Arg1& arg1, const Arg2& arg2)
{
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
}
template <typename Arg1, typename Arg2>
- void operator()(Arg1 arg1, Arg2 arg2) const
+ void operator()(const Arg1& arg1, const Arg2& arg2) const
{
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
}
template <typename Arg1, typename Arg2, typename Arg3>
- void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3)
+ void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
{
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
}
template <typename Arg1, typename Arg2, typename Arg3>
- void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3) const
+ void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
{
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
}
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
+ void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
+ const Arg4& arg4)
{
dispatcher_.dispatch(
detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
}
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) const
+ void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
+ const Arg4& arg4) const
{
dispatcher_.dispatch(
detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
@@ -98,7 +101,8 @@
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
typename Arg5>
- void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
+ void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
+ const Arg4& arg4, const Arg5& arg5)
{
dispatcher_.dispatch(
detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
@@ -106,31 +110,76 @@
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
typename Arg5>
- void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) const
+ void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
+ const Arg4& arg4, const Arg5& arg5) const
{
dispatcher_.dispatch(
detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
}
- friend void* asio_handler_allocate(std::size_t size,
- wrapped_handler<Dispatcher, Handler>* this_handler)
+//private:
+ Dispatcher& dispatcher_;
+ Handler handler_;
+};
+
+template <typename Dispatcher, typename Handler>
+inline void* asio_handler_allocate(std::size_t size,
+ wrapped_handler<Dispatcher, Handler>* this_handler)
+{
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, &this_handler->handler_);
+}
+
+template <typename Dispatcher, typename Handler>
+inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ wrapped_handler<Dispatcher, Handler>* this_handler)
+{
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, &this_handler->handler_);
+}
+
+template <typename Handler, typename Context>
+class rewrapped_handler
+{
+public:
+ explicit rewrapped_handler(const Handler& handler, const Context& context)
+ : handler_(handler),
+ context_(context)
{
- return boost_asio_handler_alloc_helpers::allocate(
- size, &this_handler->handler_);
}
- friend void asio_handler_deallocate(void* pointer, std::size_t size,
- wrapped_handler<Dispatcher, Handler>* this_handler)
+ void operator()()
{
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, &this_handler->handler_);
+ handler_();
}
-private:
- Dispatcher& dispatcher_;
+ void operator()() const
+ {
+ handler_();
+ }
+
+//private:
Handler handler_;
+ Context context_;
};
+template <typename Handler_To_Dispatch, typename Dispatcher, typename Handler>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ wrapped_handler<Dispatcher, Handler>* this_handler)
+{
+ this_handler->dispatcher_.dispatch(
+ rewrapped_handler<Handler_To_Dispatch, Handler>(
+ handler, this_handler->handler_));
+}
+
+template <typename Handler_To_Dispatch, typename Dispatcher, typename Handler>
+inline void asio_handler_dispatch(const Handler_To_Dispatch& handler,
+ rewrapped_handler<Dispatcher, Handler>* this_handler)
+{
+ boost_asio_handler_dispatch_helpers::dispatch_handler(
+ handler, &this_handler->context_);
+}
+
} // namespace detail
} // namespace asio
} // namespace boost
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs