提交 2cf06805 编写于 作者: Y youngowlf

Move async_call_indicator and related logic from st_timer to st_object.

上级 b3701b7c
......@@ -47,7 +47,7 @@ public:
//reset all, be ensure that there's no any operations performed on this st_connector_base when invoke it
//notice, when reusing this st_connector_base, st_object_pool will invoke reset(), child must re-write this to initialize
//all member variables, and then do not forget to invoke st_connector_base::reset() to initialize father's member variables
virtual void reset() {connected = false; reconnecting = true; st_tcp_socket_base<Socket, Packer, Unpacker>::reset(); ST_THIS close_state = 0;}
virtual void reset() {connected = false; reconnecting = true; st_tcp_socket_base<Socket, Packer, Unpacker>::reset();}
virtual bool obsoleted() {return !reconnecting && st_tcp_socket_base<Socket, Packer, Unpacker>::obsoleted();}
bool set_server_addr(unsigned short port, const std::string& ip = ST_ASIO_SERVER_IP)
......@@ -116,7 +116,7 @@ protected:
if (!ST_THIS get_io_service().stopped())
{
if (reconnecting && !is_connected())
ST_THIS lowest_layer().async_connect(server_addr, boost::bind(&st_connector_base::connect_handler, this, boost::asio::placeholders::error));
ST_THIS lowest_layer().async_connect(server_addr, ST_THIS make_handler_error(boost::bind(&st_connector_base::connect_handler, this, boost::asio::placeholders::error)));
else
ST_THIS do_recv_msg();
......
/*
* st_asio_wrapper_object.h
*
* Created on: 2016-6-11
* Author: youngwolf
* email: mail2tao@163.com
* QQ: 676218192
* Community on QQ: 198941541
*
* the top class
*/
#ifndef ST_ASIO_WRAPPER_OBJECT_H_
#define ST_ASIO_WRAPPER_OBJECT_H_
#include <boost/function.hpp>
#include "st_asio_wrapper_base.h"
namespace st_asio_wrapper
{
class st_object
{
protected:
st_object(boost::asio::io_service& _io_service_) : io_service_(_io_service_) {reset();}
virtual ~st_object() {}
public:
boost::asio::io_service& get_io_service() {return io_service_;}
const boost::asio::io_service& get_io_service() const {return io_service_;}
#ifdef ST_ASIO_ENHANCED_STABILITY
void post(const boost::function<void()>& handler) {io_service_.post(boost::bind(&st_object::post_handler, this, async_call_indicator, handler));}
bool is_async_calling() const {return !async_call_indicator.unique();}
boost::function<void(const boost::system::error_code&)> make_handler_error(const boost::function<void(const boost::system::error_code&)>& handler) const
{return boost::bind(&st_object::error_handler, this, async_call_indicator, handler, boost::asio::placeholders::error);}
boost::function<void(const boost::system::error_code&, size_t)> make_handler_error_size(const boost::function<void(const boost::system::error_code&, size_t)>& handler) const
{return boost::bind(&st_object::error_size_handler, this, async_call_indicator, handler, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred);}
protected:
void reset() {async_call_indicator = boost::make_shared<char>('\0');}
void post_handler(const boost::shared_ptr<char>& unused, const boost::function<void()>& handler) const {handler();}
void error_handler(const boost::shared_ptr<char>& unused, const boost::function<void(const boost::system::error_code&)>& handler,
const boost::system::error_code& ec) const {handler(ec);}
void error_size_handler(const boost::shared_ptr<char>& unused, const boost::function<void(const boost::system::error_code&, size_t)>& handler,
const boost::system::error_code& ec, size_t bytes_transferred) const {handler(ec, bytes_transferred);}
protected:
boost::shared_ptr<char> async_call_indicator;
#else
template<typename CompletionHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void())
post(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) {io_service_.post(handler);}
bool is_async_calling() const {return false;}
template<typename F>
inline const F& make_handler_error(const F& f) const {return f;}
template<typename F>
inline const F& make_handler_error_size(const F& f) const {return f;}
protected:
void reset() {}
#endif
protected:
boost::asio::io_service& io_service_;
};
} //namespace
#endif /* ifndef ST_ASIO_WRAPPER_OBJECT_H_ */
......@@ -42,7 +42,7 @@ public:
//reset all, be ensure that there's no any operations performed on this socket when invoke it
//please note, when reuse this socket, st_object_pool will invoke reset(), child must re-write it to initialize all member variables,
//and then do not forget to invoke st_server_socket_base::reset() to initialize father's member variables
virtual void reset() {st_tcp_socket_base<Socket, Packer, Unpacker>::reset(); ST_THIS close_state = 0;}
virtual void reset() {st_tcp_socket_base<Socket, Packer, Unpacker>::reset();}
void disconnect() {force_close();}
void force_close()
......
......@@ -41,10 +41,11 @@ protected:
static const unsigned char TIMER_RE_DISPATCH_MSG = TIMER_BEGIN + 3;
static const unsigned char TIMER_END = TIMER_BEGIN + 10;
st_socket(boost::asio::io_service& io_service_) : st_timer(io_service_), _id(-1), next_layer_(io_service_), packer_(boost::make_shared<Packer>()) {init();}
st_socket(boost::asio::io_service& io_service_) : st_timer(io_service_), _id(-1), next_layer_(io_service_), packer_(boost::make_shared<Packer>()) {reset_state();}
template<typename Arg>
st_socket(boost::asio::io_service& io_service_, Arg& arg) : st_timer(io_service_), _id(-1), next_layer_(io_service_, arg), packer_(boost::make_shared<Packer>()) {init();}
st_socket(boost::asio::io_service& io_service_, Arg& arg) : st_timer(io_service_), _id(-1), next_layer_(io_service_, arg), packer_(boost::make_shared<Packer>()) {reset_state();}
void reset() {reset_state(); clear_buffer(); st_timer::reset();}
void reset_state()
{
posting = false;
......@@ -310,12 +311,6 @@ protected:
return true;
}
void init()
{
reset_state();
st_timer::init();
}
private:
bool timer_handler(unsigned char id)
{
......
......@@ -63,9 +63,10 @@ protected:
if (!ST_THIS get_io_service().stopped())
{
if (ST_THIS reconnecting && !ST_THIS is_connected())
ST_THIS lowest_layer().async_connect(ST_THIS server_addr, boost::bind(&st_ssl_connector_base::connect_handler, this, boost::asio::placeholders::error));
ST_THIS lowest_layer().async_connect(ST_THIS server_addr, ST_THIS make_handler_error(boost::bind(&st_ssl_connector_base::connect_handler, this, boost::asio::placeholders::error)));
else if (!authorized_)
ST_THIS next_layer().async_handshake(boost::asio::ssl::stream_base::client, boost::bind(&st_ssl_connector_base::handshake_handler, this, boost::asio::placeholders::error));
ST_THIS next_layer().async_handshake(boost::asio::ssl::stream_base::client, ST_THIS make_handler_error(boost::bind(&st_ssl_connector_base::handshake_handler, this,
boost::asio::placeholders::error)));
else
ST_THIS do_recv_msg();
......
......@@ -42,15 +42,15 @@ protected:
using st_socket<Socket, Packer, Unpacker>::TIMER_BEGIN;
using st_socket<Socket, Packer, Unpacker>::TIMER_END;
st_tcp_socket_base(boost::asio::io_service& io_service_) : st_socket<Socket, Packer, Unpacker>(io_service_), unpacker_(boost::make_shared<Unpacker>()) {reset_state(); close_state = 0;}
st_tcp_socket_base(boost::asio::io_service& io_service_) : st_socket<Socket, Packer, Unpacker>(io_service_), unpacker_(boost::make_shared<Unpacker>()), close_state(0) {}
template<typename Arg>
st_tcp_socket_base(boost::asio::io_service& io_service_, Arg& arg) : st_socket<Socket, Packer, Unpacker>(io_service_, arg), unpacker_(boost::make_shared<Unpacker>()) {reset_state(); close_state = 0;}
st_tcp_socket_base(boost::asio::io_service& io_service_, Arg& arg) : st_socket<Socket, Packer, Unpacker>(io_service_, arg), unpacker_(boost::make_shared<Unpacker>()), close_state(0) {}
public:
virtual bool obsoleted() {return !is_closing() && st_socket<Socket, Packer, Unpacker>::obsoleted();}
//reset all, be ensure that there's no any operations performed on this st_tcp_socket_base when invoke it
void reset() {reset_state(); ST_THIS clear_buffer();}
void reset() {reset_state(); close_state = 0; st_socket<Socket, Packer, Unpacker>::reset();}
void reset_state()
{
unpacker_->reset_state();
......@@ -123,11 +123,7 @@ protected:
ST_THIS sending = true;
ST_THIS last_send_msg.swap(ST_THIS send_msg_buffer.front());
boost::asio::async_write(ST_THIS next_layer(), boost::asio::buffer(ST_THIS last_send_msg.data(), ST_THIS last_send_msg.size()),
boost::bind(&st_tcp_socket_base::send_handler, this,
#ifdef ST_ASIO_ENHANCED_STABILITY
ST_THIS async_call_indicator,
#endif
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
ST_THIS make_handler_error_size(boost::bind(&st_tcp_socket_base::send_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)));
ST_THIS send_msg_buffer.pop_front();
}
......@@ -140,11 +136,7 @@ protected:
if (boost::asio::buffer_size(recv_buff) > 0)
boost::asio::async_read(ST_THIS next_layer(), recv_buff,
boost::bind(&i_unpacker<out_msg_type>::completion_condition, unpacker_, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred),
boost::bind(&st_tcp_socket_base::recv_handler, this,
#ifdef ST_ASIO_ENHANCED_STABILITY
ST_THIS async_call_indicator,
#endif
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
ST_THIS make_handler_error_size(boost::bind(&st_tcp_socket_base::recv_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)));
}
virtual bool is_send_allowed() const {return !is_closing() && st_socket<Socket, Packer, Unpacker>::is_send_allowed();}
......@@ -175,11 +167,7 @@ protected:
}
private:
void recv_handler(
#ifdef ST_ASIO_ENHANCED_STABILITY
const boost::shared_ptr<char>& async_call_indicator,
#endif
const boost::system::error_code& ec, size_t bytes_transferred)
void recv_handler(const boost::system::error_code& ec, size_t bytes_transferred)
{
if (!ec && bytes_transferred > 0)
{
......@@ -197,15 +185,11 @@ private:
ST_THIS on_recv_error(ec);
}
void send_handler(
#ifdef ST_ASIO_ENHANCED_STABILITY
const boost::shared_ptr<char>& async_call_indicator,
#endif
const boost::system::error_code& ec, size_t bytes_transferred)
void send_handler(const boost::system::error_code& ec, size_t bytes_transferred)
{
if (!ec)
{
assert(bytes_transferred > 0);
assert(bytes_transferred == ST_THIS last_send_msg.size());
#ifdef ST_ASIO_WANT_MSG_SEND_NOTIFY
ST_THIS on_msg_send(ST_THIS last_send_msg);
#endif
......
......@@ -14,9 +14,8 @@
#define ST_ASIO_WRAPPER_TIMER_H_
#include <boost/container/set.hpp>
#include <boost/function.hpp>
#include "st_asio_wrapper_base.h"
#include "st_asio_wrapper_object.h"
//If you inherit a class from class X, your own timer ids must begin from X::TIMER_END
namespace st_asio_wrapper
......@@ -30,7 +29,7 @@ namespace st_asio_wrapper
//same st_timer, same timer, on_timer is called sequentially
//same st_timer, different timer, on_timer is called concurrently
//different st_timer, on_timer is always called concurrently
class st_timer
class st_timer : public st_object
{
protected:
struct timer_info
......@@ -48,7 +47,7 @@ protected:
static const unsigned char TIMER_END = 0; //user timer's id must begin from parent class' TIMER_END
st_timer(boost::asio::io_service& _io_service_) : io_service_(_io_service_) {}
st_timer(boost::asio::io_service& _io_service_) : st_object(_io_service_) {}
virtual ~st_timer() {}
public:
......@@ -56,15 +55,6 @@ public:
typedef const object_type object_ctype;
typedef boost::container::set<object_type> container_type;
#ifdef ST_ASIO_ENHANCED_STABILITY
void post(const boost::function<void()>& handler) {io_service_.post(boost::bind(&st_timer::post_handler, this, async_call_indicator, handler));}
bool is_async_calling() const {return !async_call_indicator.unique();}
#else
template<typename CompletionHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) post(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) {io_service_.post(handler);}
bool is_async_calling() const {return false;}
#endif
//after this call, call_back cannot be used again, please note.
void update_timer_info(unsigned char id, size_t milliseconds, boost::function<bool(unsigned char)>& call_back, bool start = false)
{
......@@ -79,7 +69,7 @@ public:
iter = timer_can.insert(ti).first;
timer_can_mutex.unlock();
iter->timer = boost::make_shared<boost::asio::deadline_timer>(boost::ref(io_service_));
iter->timer = boost::make_shared<boost::asio::deadline_timer>(boost::ref(get_io_service()));
}
else
timer_can_mutex.unlock_upgrade();
......@@ -139,30 +129,18 @@ public:
}
}
boost::asio::io_service& get_io_service() {return io_service_;}
const boost::asio::io_service& get_io_service() const {return io_service_;}
DO_SOMETHING_TO_ALL_MUTEX(timer_can, timer_can_mutex)
DO_SOMETHING_TO_ONE_MUTEX(timer_can, timer_can_mutex)
void stop_all_timer() {do_something_to_all(boost::bind((void (st_timer::*) (object_type&)) &st_timer::stop_timer, this, _1));}
protected:
#ifdef ST_ASIO_ENHANCED_STABILITY
void init() {async_call_indicator = boost::make_shared<char>('\0');}
void post_handler(const boost::shared_ptr<char>& async_call_indicator, const boost::function<void()>& handler) {handler();}
#else
void init() {}
#endif
void reset() {st_object::reset();}
void start_timer(object_ctype& ti)
{
ti.timer->expires_from_now(boost::posix_time::milliseconds(ti.milliseconds));
ti.timer->async_wait(boost::bind(&st_timer::timer_handler, this,
#ifdef ST_ASIO_ENHANCED_STABILITY
async_call_indicator,
#endif
boost::asio::placeholders::error, boost::ref(ti)));
ti.timer->async_wait(make_handler_error(boost::bind(&st_timer::timer_handler, this, boost::asio::placeholders::error, boost::ref(ti))));
}
void stop_timer(object_type& ti)
......@@ -172,24 +150,15 @@ protected:
ti.status = object_type::TIMER_CANCELED;
}
void timer_handler(
#ifdef ST_ASIO_ENHANCED_STABILITY
const boost::shared_ptr<char>& async_call_indicator,
#endif
const boost::system::error_code& ec, object_ctype& ti)
void timer_handler(const boost::system::error_code& ec, object_ctype& ti)
{
//return true from call_back to continue the timer, or the timer will stop
if (!ec && ti.call_back(ti.id) && object_type::TIMER_OK == ti.status)
start_timer(ti);
}
boost::asio::io_service& io_service_;
container_type timer_can;
boost::shared_mutex timer_can_mutex;
#ifdef ST_ASIO_ENHANCED_STABILITY
boost::shared_ptr<char> async_call_indicator;
#endif
};
} //namespace
......
......@@ -47,8 +47,7 @@ public:
using st_socket<Socket, Packer, Unpacker, udp_msg<typename Packer::msg_type>, udp_msg<typename Unpacker::msg_type> >::TIMER_BEGIN;
using st_socket<Socket, Packer, Unpacker, udp_msg<typename Packer::msg_type>, udp_msg<typename Unpacker::msg_type> >::TIMER_END;
st_udp_socket_base(boost::asio::io_service& io_service_) : st_socket<Socket, Packer, Unpacker, in_msg_type, out_msg_type>(io_service_), unpacker_(boost::make_shared<Unpacker>())
{ST_THIS reset_state();}
st_udp_socket_base(boost::asio::io_service& io_service_) : st_socket<Socket, Packer, Unpacker, in_msg_type, out_msg_type>(io_service_), unpacker_(boost::make_shared<Unpacker>()) {}
//reset all, be ensure that there's no any operations performed on this st_udp_socket when invoke it
//please note, when reuse this st_udp_socket, st_object_pool will invoke reset(), child must re-write this to initialize
......@@ -56,9 +55,6 @@ public:
//member variables
virtual void reset()
{
ST_THIS reset_state();
ST_THIS clear_buffer();
boost::system::error_code ec;
ST_THIS lowest_layer().close(ec);
ST_THIS lowest_layer().open(local_addr.protocol(), ec); assert(!ec);
......@@ -68,6 +64,8 @@ public:
ST_THIS lowest_layer().bind(local_addr, ec); assert(!ec);
if (ec)
unified_out::error_out("bind failed.");
st_socket<Socket, Packer, Unpacker, in_msg_type, out_msg_type>::reset();
}
bool set_local_addr(unsigned short port, const std::string& ip = std::string())
......@@ -138,11 +136,7 @@ protected:
ST_THIS sending = true;
ST_THIS last_send_msg.swap(ST_THIS send_msg_buffer.front());
ST_THIS next_layer().async_send_to(boost::asio::buffer(ST_THIS last_send_msg.data(), ST_THIS last_send_msg.size()), ST_THIS last_send_msg.peer_addr,
boost::bind(&st_udp_socket_base::send_handler, this,
#ifdef ST_ASIO_ENHANCED_STABILITY
ST_THIS async_call_indicator,
#endif
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
ST_THIS make_handler_error_size(boost::bind(&st_udp_socket_base::send_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)));
ST_THIS send_msg_buffer.pop_front();
}
......@@ -152,11 +146,7 @@ protected:
virtual void do_recv_msg()
{
ST_THIS next_layer().async_receive_from(unpacker_->prepare_next_recv(), peer_addr,
boost::bind(&st_udp_socket_base::recv_handler, this,
#ifdef ST_ASIO_ENHANCED_STABILITY
ST_THIS async_call_indicator,
#endif
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
ST_THIS make_handler_error_size(boost::bind(&st_udp_socket_base::recv_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)));
}
virtual bool is_send_allowed() const {return ST_THIS lowest_layer().is_open() && st_socket<Socket, Packer, Unpacker, in_msg_type, out_msg_type>::is_send_allowed();}
......@@ -188,11 +178,7 @@ protected:
}
private:
void recv_handler(
#ifdef ST_ASIO_ENHANCED_STABILITY
const boost::shared_ptr<char>& async_call_indicator,
#endif
const boost::system::error_code& ec, size_t bytes_transferred)
void recv_handler(const boost::system::error_code& ec, size_t bytes_transferred)
{
if (!ec && bytes_transferred > 0)
{
......@@ -208,15 +194,11 @@ private:
on_recv_error(ec);
}
void send_handler(
#ifdef ST_ASIO_ENHANCED_STABILITY
const boost::shared_ptr<char>& async_call_indicator,
#endif
const boost::system::error_code& ec, size_t bytes_transferred)
void send_handler(const boost::system::error_code& ec, size_t bytes_transferred)
{
if (!ec)
{
assert(bytes_transferred > 0);
assert(bytes_transferred == ST_THIS last_send_msg.size());
#ifdef ST_ASIO_WANT_MSG_SEND_NOTIFY
ST_THIS on_msg_send(ST_THIS last_send_msg);
#endif
......
......@@ -116,7 +116,7 @@ protected:
if (!ST_THIS get_io_service().stopped())
{
if (reconnecting && !is_connected())
ST_THIS lowest_layer().async_connect(server_addr, boost::bind(&st_connector_base::connect_handler, this, boost::asio::placeholders::error));
ST_THIS lowest_layer().async_connect(server_addr, ST_THIS make_handler_error(boost::bind(&st_connector_base::connect_handler, this, boost::asio::placeholders::error)));
else
ST_THIS do_recv_msg();
......
......@@ -13,8 +13,6 @@
#ifndef ST_ASIO_WRAPPER_OBJECT_H_
#define ST_ASIO_WRAPPER_OBJECT_H_
#include <boost/function.hpp>
#include "st_asio_wrapper_base.h"
namespace st_asio_wrapper
......@@ -31,15 +29,19 @@ public:
const boost::asio::io_service& get_io_service() const {return io_service_;}
template<typename CompletionHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void())
#ifdef ST_ASIO_ENHANCED_STABILITY
post(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) {auto unused(ST_THIS async_call_indicator); io_service_.post([=]() {handler();});}
bool is_async_calling() const {return !async_call_indicator.unique();}
std::function<void(const boost::system::error_code&)> make_handler_error(const std::function<void(const boost::system::error_code&)>& handler)
std::function<void(const boost::system::error_code&)> make_handler_error(std::function<void(const boost::system::error_code&)>&& handler) const
{boost::shared_ptr<char>unused(async_call_indicator); return [=](const boost::system::error_code& ec) {handler(ec);};}
std::function<void(const boost::system::error_code&)> make_handler_error(const std::function<void(const boost::system::error_code&)>& handler) const
{boost::shared_ptr<char>unused(async_call_indicator); return [=](const boost::system::error_code& ec) {handler(ec);};}
std::function<void(const boost::system::error_code&, size_t)> make_handler_error_size(const std::function<void(const boost::system::error_code&, size_t)>& handler)
std::function<void(const boost::system::error_code&, size_t)> make_handler_error_size(std::function<void(const boost::system::error_code&, size_t)>&& handler) const
{boost::shared_ptr<char>unused(async_call_indicator); return [=](const boost::system::error_code& ec, size_t bytes_transferred) {handler(ec, bytes_transferred);};}
std::function<void(const boost::system::error_code&, size_t)> make_handler_error_size(const std::function<void(const boost::system::error_code&, size_t)>& handler) const
{boost::shared_ptr<char>unused(async_call_indicator); return [=](const boost::system::error_code& ec, size_t bytes_transferred) {handler(ec, bytes_transferred);};}
protected:
......@@ -52,10 +54,14 @@ protected:
bool is_async_calling() const {return false;}
template<typename F>
const F& make_handler_error(const F& f) {return f;}
inline F&& make_handler_error(F&& f) const {return std::move(f);}
template<typename F>
inline const F& make_handler_error(const F& f) const {return f;}
template<typename F>
const F& make_handler_error_size(const F& f) {return f;}
inline F&& make_handler_error_size(F&& f) const {return std::move(f);}
template<typename F>
inline const F& make_handler_error_size(const F& f) const {return f;}
protected:
void reset() {}
......
......@@ -63,9 +63,10 @@ protected:
if (!ST_THIS get_io_service().stopped())
{
if (ST_THIS reconnecting && !ST_THIS is_connected())
ST_THIS lowest_layer().async_connect(ST_THIS server_addr, boost::bind(&st_ssl_connector_base::connect_handler, this, boost::asio::placeholders::error));
ST_THIS lowest_layer().async_connect(ST_THIS server_addr, ST_THIS make_handler_error(boost::bind(&st_ssl_connector_base::connect_handler, this, boost::asio::placeholders::error)));
else if (!authorized_)
ST_THIS next_layer().async_handshake(boost::asio::ssl::stream_base::client, boost::bind(&st_ssl_connector_base::handshake_handler, this, boost::asio::placeholders::error));
ST_THIS next_layer().async_handshake(boost::asio::ssl::stream_base::client, ST_THIS make_handler_error(boost::bind(&st_ssl_connector_base::handshake_handler, this,
boost::asio::placeholders::error)));
else
ST_THIS do_recv_msg();
......
......@@ -16,7 +16,6 @@
#include <boost/container/set.hpp>
#include "st_asio_wrapper_object.h"
#include "st_asio_wrapper_base.h"
//If you inherit a class from class X, your own timer ids must begin from X::TIMER_END
namespace st_asio_wrapper
......@@ -40,7 +39,7 @@ protected:
unsigned char id;
timer_status status;
size_t milliseconds;
boost::function<bool(unsigned char)> call_back;
std::function<bool(unsigned char)> call_back;
boost::shared_ptr<boost::asio::deadline_timer> timer;
bool operator <(const timer_info& other) const {return id < other.id;}
......@@ -56,7 +55,7 @@ public:
typedef const object_type object_ctype;
typedef boost::container::set<object_type> container_type;
void update_timer_info(unsigned char id, size_t milliseconds, boost::function<bool(unsigned char)>&& call_back, bool start = false)
void update_timer_info(unsigned char id, size_t milliseconds, std::function<bool(unsigned char)>&& call_back, bool start = false)
{
object_type ti = {id};
......@@ -82,11 +81,11 @@ public:
if (start)
start_timer(*iter);
}
void update_timer_info(unsigned char id, size_t milliseconds, const boost::function<bool(unsigned char)>& call_back, bool start = false)
{update_timer_info(id, milliseconds, boost::function<bool(unsigned char)>(call_back), start);}
void update_timer_info(unsigned char id, size_t milliseconds, const std::function<bool(unsigned char)>& call_back, bool start = false)
{update_timer_info(id, milliseconds, std::function<bool(unsigned char)>(call_back), start);}
void set_timer(unsigned char id, size_t milliseconds, boost::function<bool(unsigned char)>&& call_back) {update_timer_info(id, milliseconds, std::move(call_back), true);}
void set_timer(unsigned char id, size_t milliseconds, const boost::function<bool(unsigned char)>& call_back) {update_timer_info(id, milliseconds, call_back, true);}
void set_timer(unsigned char id, size_t milliseconds, std::function<bool(unsigned char)>&& call_back) {update_timer_info(id, milliseconds, std::move(call_back), true);}
void set_timer(unsigned char id, size_t milliseconds, const std::function<bool(unsigned char)>& call_back) {update_timer_info(id, milliseconds, call_back, true);}
object_type find_timer(unsigned char id)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册