AsioC++網(wǎng)絡(luò)和IO開發(fā)包
Asio 是一個(gè)跨平臺(tái)的C++開發(fā)包用來處理網(wǎng)絡(luò)和低級(jí)I/O編程,通過先進(jìn)的C++方法為開發(fā)人員提供連續(xù)異步模型。
示例代碼:
void handle_read(const asio::error_code& error,
size_t bytes_transferred)
{
if (!error)
{
asio::async_write(socket_,
asio::buffer(data_, bytes_transferred),
make_custom_alloc_handler(allocator_,
boost::bind(&session::handle_write,
shared_from_this(),
asio::placeholders::error)));
}
}
void handle_write(const asio::error_code& error)
{
if (!error)
{
socket_.async_read_some(asio::buffer(data_),
make_custom_alloc_handler(allocator_,
boost::bind(&session::handle_read,
shared_from_this(),
asio::placeholders::error,
asio::placeholders::bytes_transferred)));
}
}
