简体   繁体   English

可以boost :: asio :: async_read_until检测到无尽的流

[英]Can boost::asio::async_read_until detect an endless stream

I am using boost::asio::async_read_until to read a message from a socket, using a newline as a delimiter. 我正在使用boost :: asio :: async_read_until从套接字读取消息,并使用换行符作为分隔符。

eg boost::asio::async_read_until(socket, buffer, "\\n", .....) 例如boost :: asio :: async_read_until(socket,buffer,“ \\ n”,.....)

Everything is hunkey dorey and works fine. 一切都是亨基·多雷,一切正常。

Is there an alternative way to use this function, or a similar one, that can detect an endless sequence of characters that do not have a newline constant in them. 是否有其他方法可以使用此功能或类似的功能,该功能可以检测字符中没有换行常量的无穷字符序列。

eg a malicious user might fire a continuous sequence of ZEROS at my server 例如,恶意用户可能会在我的服务器上发射连续的ZEROS序列

socat /dev/zero TCP4:localhost:55555 socat / dev / zero TCP4:localhost:55555

I can't be the first person in history to have come across this problem 我不能成为历史上第一个遇到这个问题的人

You can use version 4 of the 4 overloads: 您可以使用4个重载中的版本4:

http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/reference/async_read_until/overload4.html http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/reference/async_read_until/overload4.html

In your function object, which would normally be an interface to a state machine, you can count characters, detect illegal data streams or any other means necessary. 在功能对象(通常是状态机的接口)中,您可以计算字符,检测非法数据流或任何其他必要方式。

It's probably worth mentioning that if your application is running in a hostile environment (ie internet-facing) then you will probably want to use async_read_some to feed your state machine and will want a timer to catch and kill connections that sit and consume resources. 值得一提的是,如果您的应用程序在敌对环境(即面向Internet)中运行,那么您可能希望使用async_read_some来馈送您的状态机,并希望使用计时器来捕获并杀死占用并占用资源的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM