本文介绍了动态大小的boost :: asio :: buffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样从boost::asio::ip::udp::socket中读取内容:

I'm reading from a boost::asio::ip::udp::socket like this:

using boost::asio::ip::udp;

// ...

char recv_buf[128];
udp::endpoint sender_endpoint;
size_t len = socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint);

现在,这可以正常工作,但是我现在可以接收的最大字符数为127.但是,我遇到了一个问题,因为我需要接受一些长度可能相差很大的数据输入(并且例如,长度不明确,带有前缀标头).一种解决方案是动态扩展缓冲区,例如向量.是否可以创建一个动态扩展的boost::asio::buffer来接受(理论上)无限量的输入并将其存储在容器中?

Now, this works perfectly fine, but the maximum amount of characters that I am able to recieve is now 127. However I am facing a problem because I need to accept some data input of which the length can greatly vary (and is not of well-defined length with prefixed headers, for example). A solution to this would be a dynamically expanding buffer, like a vector. Is it possible to create a dynamically expanding boost::asio::buffer to accept (theoretical) infite amounts of input and store it in a container?

推荐答案

UDP数据报的大小并没有太大变化:它永远不会大于 65535 ,在8字节标头之后留出65,527字节数据的空间.

UDP datagram size does not vary all that greatly: it will never be greater than 65535, leaving room for 65,527 bytes of data after the 8-byte header.

这篇关于动态大小的boost :: asio :: buffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:20