use handler allocator for UDP socket read handler
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright (c) 2015, Arvid Norberg
|
Copyright (c) 2015, Arvid Norberg, Daniel Wallin
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@@ -97,6 +97,11 @@ namespace libtorrent { namespace aux
|
|||||||
handler(std::forward<A>(a)...);
|
handler(std::forward<A>(a)...);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
void operator()() const
|
||||||
|
{
|
||||||
|
handler();
|
||||||
|
}
|
||||||
|
|
||||||
template <class A0>
|
template <class A0>
|
||||||
void operator()(A0 const& a0) const
|
void operator()(A0 const& a0) const
|
||||||
{
|
{
|
||||||
|
@@ -983,7 +983,7 @@ namespace libtorrent
|
|||||||
// have sent to it
|
// have sent to it
|
||||||
int m_outstanding_bytes;
|
int m_outstanding_bytes;
|
||||||
|
|
||||||
// TODO: 3 use handler storage for second_tick and udp_packet handler too
|
// TODO: 3 use handler storage for second_tick too
|
||||||
aux::handler_storage<TORRENT_READ_HANDLER_MAX_SIZE> m_read_handler_storage;
|
aux::handler_storage<TORRENT_READ_HANDLER_MAX_SIZE> m_read_handler_storage;
|
||||||
aux::handler_storage<TORRENT_WRITE_HANDLER_MAX_SIZE> m_write_handler_storage;
|
aux::handler_storage<TORRENT_WRITE_HANDLER_MAX_SIZE> m_write_handler_storage;
|
||||||
|
|
||||||
|
@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "libtorrent/thread.hpp"
|
#include "libtorrent/thread.hpp"
|
||||||
#include "libtorrent/deadline_timer.hpp"
|
#include "libtorrent/deadline_timer.hpp"
|
||||||
#include "libtorrent/debug.hpp"
|
#include "libtorrent/debug.hpp"
|
||||||
|
#include "libtorrent/aux_/allocating_handler.hpp"
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
@@ -175,6 +176,29 @@ namespace libtorrent
|
|||||||
udp_socket(udp_socket const&);
|
udp_socket(udp_socket const&);
|
||||||
udp_socket& operator=(udp_socket const&);
|
udp_socket& operator=(udp_socket const&);
|
||||||
|
|
||||||
|
template <class Handler>
|
||||||
|
aux::allocating_handler<Handler, TORRENT_READ_HANDLER_MAX_SIZE>
|
||||||
|
make_read_handler(udp::socket* s, Handler const& handler)
|
||||||
|
{
|
||||||
|
#if TORRENT_USE_IPV6
|
||||||
|
if (s == &m_ipv6_sock)
|
||||||
|
{
|
||||||
|
return aux::allocating_handler<Handler, TORRENT_READ_HANDLER_MAX_SIZE>(
|
||||||
|
handler, m_read6_handler_storage);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return aux::allocating_handler<Handler, TORRENT_READ_HANDLER_MAX_SIZE>(
|
||||||
|
handler, m_read4_handler_storage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aux::handler_storage<TORRENT_READ_HANDLER_MAX_SIZE> m_read4_handler_storage;
|
||||||
|
#if TORRENT_USE_IPV6
|
||||||
|
aux::handler_storage<TORRENT_READ_HANDLER_MAX_SIZE> m_read6_handler_storage;
|
||||||
|
#endif
|
||||||
|
|
||||||
// observers on this udp socket
|
// observers on this udp socket
|
||||||
std::vector<udp_socket_observer*> m_observers;
|
std::vector<udp_socket_observer*> m_observers;
|
||||||
std::vector<udp_socket_observer*> m_added_observers;
|
std::vector<udp_socket_observer*> m_added_observers;
|
||||||
|
@@ -501,7 +501,7 @@ void udp_socket::setup_read(udp::socket* s)
|
|||||||
TORRENT_TRY
|
TORRENT_TRY
|
||||||
{
|
{
|
||||||
s->async_receive_from(null_buffers()
|
s->async_receive_from(null_buffers()
|
||||||
, ep, boost::bind(&udp_socket::on_read, this, _1, s));
|
, ep, make_read_handler(s, boost::bind(&udp_socket::on_read, this, _1, s)));
|
||||||
}
|
}
|
||||||
TORRENT_CATCH(boost::system::system_error& e)
|
TORRENT_CATCH(boost::system::system_error& e)
|
||||||
{
|
{
|
||||||
@@ -510,8 +510,8 @@ void udp_socket::setup_read(udp::socket* s)
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
boost::system::system_error e(ec);
|
boost::system::system_error e(ec);
|
||||||
#endif
|
#endif
|
||||||
get_io_service().post(boost::bind(&udp_socket::on_read
|
get_io_service().post(make_read_handler(s, boost::bind(&udp_socket::on_read
|
||||||
, this, e.code(), s));
|
, this, e.code(), s)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user