维护回调函数之间的状态
换句话来说,
我是 haskell 的新手。我正在尝试使用网络 pcap 包解析 pcap 文件。
我有字节流作为输入,所以我使用了dispatchBS函数和我自己的回调函数。
我的目标是获得所有回调的串联结果。 [a] 已解析的所有数据包。当dispatchBS的签名中没有任何内容来维护迄今为止解析的所有数据包的状态时,如何跟踪迄今为止获得的所有数据包?
http://hackage .haskell.org/packages/archive/pcap/0.4.5/doc/html/Network-Pcap.html#t:CallbackBS
To Rephrase
I am newbie to haskell. I am trying to parse a pcap file using network pcap package.
I have byte stream as an input, so I used dispatchBS function with my own callback function.
My goal is to get the concatenated result from all callbacks. [a] of all the packets parsed. How do I keep track of all the packets got so far when dispatchBS has nothing in its signature to maintain state of all packets parsed so far?
http://hackage.haskell.org/packages/archive/pcap/0.4.5/doc/html/Network-Pcap.html#t:CallbackBS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,您可以使用“loop”函数并提供您自己的回调。此回调必须是 IO 操作,因此一种简单的解决方案是将其数据包参数附加到 IORef 中保存的序列(请参阅 Data.Sequence)。一旦收到足够的数据包,只需读取 IOVar。或者,您可以使用线程和队列做一些更复杂的事情,具体取决于您想要实现的目标。
For example, you might use the "loop" function and provide your own callback. This callback has to be an IO action, so one simple solution would be to have it append its packet argument to a sequence (see Data.Sequence) held in an IORef. Once you have received enough packets, just read the IOVar. Or you could do something more sophisticated with threads and queues, depending on what you are trying to achieve.