下载最新版 non_boost
linux下 ./configure --without-boost
make && make install
然后就可以使用了。
测试代码:
1 #include "asio.hpp"
2 #include <iostream>
3 #include <vector>
4
5 class TcpServer
6 {
7 public:
8 TcpServer(int thread_num, int port, int buff_size)
9 {
10 pcontext_ = new asio::io_context(thread_num);
11 pacc_ = new asio::ip::tcp::acceptor(*pcontext_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port));
12 sock_ = new asio::ip::tcp::socket(pacc_->get_executor());
13 }
14
15 void start()
16 {
17 std::cout << "asio poll begin\n";
18 pcontext_->run();
19 }
20 private:
21 asio::io_context* pcontext_;
22 asio::ip::tcp::acceptor* pacc_;
23 asio::ip::tcp::socket* sock_;
24 std::vector<unsigned char> buffer_;
25 asio::ip::tcp::endpoint sender_;
26 };
27 int main()
28 {
29 TcpServer ts(1, 9000, 1024);
30 ts.start();
31 std::cout << "asio test" << std::endl;
32 }
加断点调试
asio::io_context::run (this=0x61c040) at /usr/local/include/asio/impl/io_context.ipp:61
asio::detail::scheduler::run (this=0x61c0b0, ec=...) at /usr/local/include/asio/detail/impl/scheduler.ipp:189