提高:: ASIO - 偷看套接字缓冲区 [英] boost::asio - peeking into a socket buffer

查看:305
本文介绍了提高:: ASIO - 偷看套接字缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用boost :: ASIO ::读取(或可能是等价的 async_read )从套接字读取一些数据。

I use boost::asio::read (or may be the equivalent async_read) to read some data from a socket.

难道我留在基础套接字读取的字节数,这样下一次我打电话,我再次收到数据套接字上读?

Is it possible that I leave the bytes read in the underlying socket so that next time I call read on the socket I receive again that data ?

推荐答案

像西蒙说,你不能用做的boost :: ASIO ::阅读() (或提高:: ASIO :: async_read())。然而,对于阅读()你可以调用函数native_handle()插座,以获得socket描述符,再使用 :: recvmsg() MSG_PEEK 标记。同样,你可以调用 async_read() null_buffers()作为接收缓冲区,然后使用函数native_handle() / :: recvmsg()诱骗偷看的数据。请查看本节如何使用null_buffers()。

Like Simon said, you can't do it with boost::asio::read() (or boost::asio::async_read()). However, for read() you could call native_handle() on the socket to get the socket descriptor and then use ::recvmsg() with the MSG_PEEK flag. Similarly, you could call async_read() with null_buffers() as the receive buffer and then use the native_handle()/::recvmsg() trick to peek the data. Check out this section of the boost documentation for how to use null_buffers().

这篇关于提高:: ASIO - 偷看套接字缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆