1) 不要多线程同时对一个socket 进行asio::async_write, 也不要在一个线程内对一个socket多次async_write。
理由:async_write是个异步操作,数据较大时, 会分多次调用async_write_some发送出去。 因此即便是一个线程内的多个async_write, 其async_write_some也可能交叉乱序了。
2)read_handler, write_handler、timeout_handler的参数都应该是const类型的。虽然可以定义成非const型参数、修改也不会有编译错误, 但是修改不会生效。
3)各种handler应该使用堆内存、全局变量、或者shared_from_this(), 或者类变量的成员。 不能使用栈变量; 使用栈变量的话,需要使用boost::ref进行修饰。
boost::asio::deadline_timer timer(m_ioservice);
timer.expires_from_now(boost::posix_time::seconds(0));
timer.async_wait(boost::bind(&RecIO::timeout_handler, shared_from_this(), <span style="color:#FF0000;">boost::ref(timer)</span>, int(timer_queue_type), boost::asio::placeholders::error));
4)boost_auto宏, 自动推导变量类型。 <boost/typeof.hpp>
5)boost poperty_tree解析xml
http://www.oschina.net/code/snippet_126720_4952
6)boost::call_once, 保证只被执行一次。 google protobuf中也有类似实现
http://www.oschina.net/code/snippet_54334_870