void async_write_some(Const_Buffers const& buffers, Handler const& handler) { if (m_impl == 0) { m_io_service.post(boost::bind<void>(handler, asio::error::not_connected, 0)); return; } TORRENT_ASSERT(!m_write_handler); if (m_write_handler) { m_io_service.post(boost::bind<void>(handler, asio::error::operation_not_supported, 0)); return; } for (typename Const_Buffers::const_iterator i = buffers.begin() , end(buffers.end()); i != end; ++i) { TORRENT_ASSERT(buffer_size(*i) > 0); using asio::buffer_cast; using asio::buffer_size; add_write_buffer((void*)buffer_cast<void const*>(*i), buffer_size(*i)); } m_write_handler = handler; set_write_handler(&utp_stream::on_write); }
void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) { if (m_impl == 0) { m_io_service.post(boost::bind<void>(handler, asio::error::not_connected, 0)); return; } TORRENT_ASSERT(!m_read_handler); if (m_read_handler) { m_io_service.post(boost::bind<void>(handler, asio::error::operation_not_supported, 0)); return; } int bytes_added = 0; for (typename Mutable_Buffers::const_iterator i = buffers.begin() , end(buffers.end()); i != end; ++i) { if (buffer_size(*i) == 0) continue; using asio::buffer_cast; using asio::buffer_size; add_read_buffer(buffer_cast<void*>(*i), buffer_size(*i)); bytes_added += buffer_size(*i); } if (bytes_added == 0) { // if we're reading 0 bytes, post handler immediately // asio's SSL layer depends on this behavior m_io_service.post(boost::bind<void>(handler, error_code(), 0)); return; } m_read_handler = handler; issue_read(); }
std::size_t read_some(Mutable_Buffers const& buffers, error_code& ec) { TORRENT_ASSERT(!m_read_handler); if (m_impl == 0) { ec = asio::error::not_connected; return 0; } if (read_buffer_size() == 0) { ec = asio::error::would_block; return 0; } #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS size_t buf_size = 0; #endif for (typename Mutable_Buffers::const_iterator i = buffers.begin() , end(buffers.end()); i != end; ++i) { using asio::buffer_cast; using asio::buffer_size; add_read_buffer(buffer_cast<void*>(*i), buffer_size(*i)); #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS buf_size += buffer_size(*i); #endif } std::size_t ret = read_some(true); TORRENT_ASSERT(ret <= buf_size); TORRENT_ASSERT(ret > 0); return ret; }
void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) { if (m_impl == 0) { m_io_service.post(boost::bind<void>(handler, asio::error::not_connected, 0)); return; } LIBED2K_ASSERT(!m_read_handler); if (m_read_handler) { m_io_service.post(boost::bind<void>(handler, asio::error::operation_not_supported, 0)); return; } for (typename Mutable_Buffers::const_iterator i = buffers.begin(), end(buffers.end()); i != end; ++i) { LIBED2K_ASSERT(buffer_size(*i) > 0); using asio::buffer_cast; using asio::buffer_size; add_read_buffer(buffer_cast<void*>(*i), buffer_size(*i)); } m_read_handler = handler; set_read_handler(&utp_stream::on_read); }