PacketTunnelProvider - ENOBUFS

For my VPN app for macOS, implemented with Packet Tunnel Provider, I'm using BSD sockets, over UDP, and they are non-blocking.
If I'm trying to send large files (~1GB), I'm getting the error ENOBUFS (No buffer space available).
I've tried setting SO_SNDBUF, but it didn't help.

In addition, I saw this very old discussion about this problem at macOS - https://lists.freebsd.org/pipermail/freebsd-hackers/2004-January/005369.html


Is there anything I can do to solve it? At the moment I can't send big files via my app.

Answered by Systems Engineer in 396474022

This is a difficult one because SO_SNDBUF will only have an impact on a single write with UDP as opposed to all data written to a buffer like in TCP. There are a few options here; first, I am not sure how realistic this is in your application, but I would take a look at using TCP for file transfer instead of UDP. TCP will provide you with the buffer and packet book keeping required for large sequential transmissions often needed in file transfers. Second, I would look into using a modern API such as NWConnection in Network Framework to create such file transfer connections. Network Framework will also get you away from having to use sockets and manually managing a lot of the code needed to maintain and transfer data.

Accepted Answer

This is a difficult one because SO_SNDBUF will only have an impact on a single write with UDP as opposed to all data written to a buffer like in TCP. There are a few options here; first, I am not sure how realistic this is in your application, but I would take a look at using TCP for file transfer instead of UDP. TCP will provide you with the buffer and packet book keeping required for large sequential transmissions often needed in file transfers. Second, I would look into using a modern API such as NWConnection in Network Framework to create such file transfer connections. Network Framework will also get you away from having to use sockets and manually managing a lot of the code needed to maintain and transfer data.

K, I'll check if it's possible for me to do those changes. Thanks!

PacketTunnelProvider - ENOBUFS
 
 
Q