I guess this is a question to understand the boost source code(boost::asio::detail::write_op). The code snippet from boost source code repo is as follows.
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
std::array<boost::asio::const_buffer, 2> >::type bufs = {{
boost::asio::const_buffer(buffers_[0]),
boost::asio::const_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
stream_.async_write_some(bufs, BOOST_ASIO_MOVE_CAST(write_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
In this code, I couldn't understand the purpose of default
case being placed inside the for loop. Why would one implement a case statement this way ? I am just curious.
Any explanation would be a great help.