boost asio http:asio很烂吗

531被浏览64,946分享邀请回答10314 条评论分享收藏感谢收起253 条评论分享收藏感谢收起boost asio并发最大可以是多少_百度知道
boost asio并发最大可以是多少
我有更好的答案
.建议使用一个socket专门接收数据.如果使用一个socket既发送又接收,很可能出现这样的问题(如果该socket正在接收数据,一个socket专门负责发送数据。 2,而又想同时发送数据,你会想到什么后果吗
采纳率:96%
来自团队:
为您推荐:
其他类似问题
asio的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。531被浏览64,946分享邀请回答void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
switch (start)
buffers_.prepare(this-&check_for_completion(ec, total_transferred_));
stream_.async_read_some(buffers_,
BOOST_ASIO_MOVE_CAST(read_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
buffers_.prepare(this-&check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
handler_(ec, static_cast&const std::size_t&&(total_transferred_));
69 条评论分享收藏感谢收起4565人阅读
boost(12)
阻塞等待:这里会等待3秒然后才进行输出。
#include &iostream&
#include &boost/asio.hpp&
#include &boost/date_time/posix_time/posix_time.hpp&
int main(void)
boost::asio::io_
boost::asio::deadline_timer timer(io, boost::posix_time::seconds(3));
timer.wait();
std::cout && "this is blocking wait" && std::
system("pause");
}异步等待:需要一个回调函数,在等待这个print回调函数的时候程序会继续往下执行到io.run为止,3秒过后才会执行回调函数。如果在3秒内程序还没有执行到io.run(如加上sleep(5)),那么5秒后才会执行print,也就是说在执行io.run之前print是不会执行的。#include &iostream&
#include &boost/asio.hpp&
#include &boost/date_time/posix_time/posix_time.hpp&
void print(const boost::system::error_code & e)
std::cout && "hello, world" && std::
int main(void)
boost::asio::io_
boost::asio::deadline_timer timer(io, boost::posix_time::seconds(3));
timer.async_wait(&print);
std::cout && "this is asynchronous wait" && std::
// sleep(5);
system("pause");
}// 开始timer的异步等待时间是1秒,1秒后会执行print回调函数,在这个函数里会进行5次递归调用。由于timer的
// 终止时间是1秒已经到期了所以在递归的过程中不会再每秒执行一次的,为了实现每秒输出的效果我们需要为这个
// timer延迟终止时间,expires_at就是其这个作用。当然expires_at必须在async_wait之前执行,否则是没有效果的。
#include &iostream&
#include &boost/asio.hpp&
#include &boost/date_time/posix_time/posix_time.hpp&
#include &boost/bind.hpp&
#include &windows.h&
unsigned int start_t, end_t;
void print(const boost::system::error_code& e, boost::asio::deadline_timer* timer, int* count)
if (*count & 5)
std::cout && "count: " && *count && std::
end_t = ::GetTickCount();
std::cout && "elapse time:" && end_t-start_t && std::
++(*count);
//timer-&expires_from_now(boost::posix_time::seconds(1));
timer-&expires_at(timer-&expires_at() + boost::posix_time::seconds(1));
timer-&async_wait(boost::bind(print, boost::asio::placeholders::error, timer, count));
int main()
int count = 0;
boost::asio::io_
boost::asio::deadline_timer timer(io, boost::posix_time::seconds(1));
timer.async_wait(boost::bind(print, boost::asio::placeholders::error, &timer, &count));
start_t = ::GetTickCount();
std::cout && "run end" && std::
system("pause");
}// 下面是类成员函数回调的形式
#include &iostream&
#include &boost/asio.hpp&
#include &boost/date_time/posix_time/posix_time.hpp&
#include &boost/bind.hpp&
class Printer
Printer(boost::asio::io_service& io)
: count_(0), timer_(io, boost::posix_time::seconds(1))
timer_.async_wait(boost::bind(&Printer::print, this));
~Printer()
void print()
if (count_ & 5)
std::cout && "count: " && count_ && std::
timer_.expires_from_now(boost::posix_time::seconds(1));
timer_.async_wait(boost::bind(&Printer::print, this));
int count_;
boost::asio::deadline_timer timer_;
int main()
boost::asio::io_
Printer printer(io);
system("pause");他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 boost asio read 的文章

 

随机推荐