简体   繁体   English

Android VpnService 写数据包错误 - 没有可用的缓冲区空间

[英]Android VpnService write packet error - no buffer space available

I'm writing UDP packets to a VpnService instance in Android, but I intermittently get errors like:我正在将 UDP 数据包写入 Android 中的 VpnService 实例,但我间歇性地收到如下错误:

java.io.IOException: write failed: ENOBUFS (No buffer space available)
at libcore.io.IoBridge.write(IoBridge.java:455)
at java.io.FileOutputStream.write(FileOutputStream.java:187)
at java.io.OutputStream.write(OutputStream.java:82)

There is only a single DatagramSocket that is used to send and receive packets, so I don't think I'm leaking memory.只有一个 DatagramSocket 用于发送和接收数据包,所以我不认为我在泄漏内存。 I also checked my heap usage, which remains stable at 10-12 MB.我还检查了我的堆使用情况,它保持稳定在 10-12 MB。 I don't get this error with TCP packets I'm transferring.我正在传输的 TCP 数据包没有出现此错误。 Any suggestions?有什么建议?

I just hit this problem in my own VPN implementation ( open source , if anybody wants a working example).我只是在我自己的 VPN 实现中遇到了这个问题( 开源,如果有人想要一个工作示例)。

In my case, this was because I was writing TCP packets back to the VPN interface that were larger than expected, because my code wasn't properly handling the max segment size.就我而言,这是因为我将 TCP 数据包写回比预期大的 VPN 接口,因为我的代码没有正确处理最大段大小。

This wasn't due to some general purpose buffer waiting to flush, so packets that were too large for the receiving application would fail with ENOBUFS forever.这不是由于某些通用缓冲区等待刷新,因此对于接收应用程序来说太大的数据包将永远因 ENOBUFS 而失败。

Although I can't find it documented anywhere, I expect this is the cause in general: you'll hit an ENOBUFS if you try to write any packet to the VPN that's individually larger than what the VPN expects.尽管我无法在任何地方找到它的记录,但我希望这通常是原因:如果您尝试向 VPN 写入任何比 VPN 预期大的数据包,您将遇到 ENOBUFS。

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

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