Boost.Asio学习之Buffer

本文介绍了Boost.Asio库中Buffer的概念,并通过示例详细讲解了如何使用streambuf进行网络编程,包括构造string、输出及写入到网络套接字的操作。
摘要由CSDN通过智能技术生成

详情见:http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/examples/cpp11_examples.html
或者:https://github.com/NearXdu/AsioLearn

1.示例

我们经常这样写代码:

size_t read_complete(boost::system::error_code, size_t bytes){ ... }
char buff[1024];
read(sock, boost::asio::buffer(buff), read_complete);
write(sock, buffer("echo\n"));

在example中,简单实现了一个buffer。

//
//This example demonstrates how to create reference counted buffers that can be used with socket read and write operations
#include <boost/asio.hpp>
#include <iostream>
#include <memory>
#include <utility>
#include <vector>

using namespace boost::asio;
using namespace boost::asio::ip;
class shared_const_buffer
{
    public:
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值