xilh
2014-12-22 09:35:40 UTC
dear allïŒ
I want to use coroutine and async_read_some to download data from mysql.
But I got a trouble:
when the deadline timer is expired , the application crashed.
void operator()(const error_code_t& err, std::size_t size) {
BOOST_ASIO_CORO_REENTER (*this) {
deadline_->expires_from_now(boost::posix_time::seconds(1));
deadline_->async_wait(boost::bind(&BasicSendAndRecvCo::Close, this, _1));
net_->SetPktNr(0);
BOOST_ASIO_CORO_YIELD
net_->WritePacket(sql_, sql_len_, *this);
if (err) {
LOG(ERROR) << "err:" << err;
Exit(err, 0);
return;
}
for (;;) {
data_->Extend(kMaxReadSize);
BOOST_ASIO_CORO_YIELD {
net_->socket_.async_read_some(
boost::asio::buffer(data_->read_pos(), kMaxReadSize), *this);
}
if (err) {
LOG(INFO) << "err:" << err;
Exit(err, data_->len());
return;
}
data_->len() += size;
if (complete)
break;
}
}
void Close(const boost::system::error_code& ec) {
if (ec != boost::asio::error::operation_aborted) {
net_->socket_.cancel();
}
}
â
I want to use coroutine and async_read_some to download data from mysql.
But I got a trouble:
when the deadline timer is expired , the application crashed.
void operator()(const error_code_t& err, std::size_t size) {
BOOST_ASIO_CORO_REENTER (*this) {
deadline_->expires_from_now(boost::posix_time::seconds(1));
deadline_->async_wait(boost::bind(&BasicSendAndRecvCo::Close, this, _1));
net_->SetPktNr(0);
BOOST_ASIO_CORO_YIELD
net_->WritePacket(sql_, sql_len_, *this);
if (err) {
LOG(ERROR) << "err:" << err;
Exit(err, 0);
return;
}
for (;;) {
data_->Extend(kMaxReadSize);
BOOST_ASIO_CORO_YIELD {
net_->socket_.async_read_some(
boost::asio::buffer(data_->read_pos(), kMaxReadSize), *this);
}
if (err) {
LOG(INFO) << "err:" << err;
Exit(err, data_->len());
return;
}
data_->len() += size;
if (complete)
break;
}
}
void Close(const boost::system::error_code& ec) {
if (ec != boost::asio::error::operation_aborted) {
net_->socket_.cancel();
}
}
â