开发者

Linux / C udp send methods

开发者 https://www.devze.com 2023-03-12 07:40 出处:网络
The only way to send UDP packets in C is to use send/sendo/write/... calls. The problem with those is, that for each packet I need to perform a new call from user-space.

The only way to send UDP packets in C is to use send/sendo/write/... calls.

The problem with those is, that for each packet I need to perform a new call from user-space.

Does anyone know whether there is a function which allows for something like

send_packets( int socket, const char* buffer, int packetS开发者_如何转开发ize )

Which does automatically split the data in the buffer into packets of size packetSize (e.g. 1472) and then send them as UDP packets?

Thanks


You can batch raw packets but not higher level protocols. The low-level API is for utilities like Wireshark.

On Linux you can modify the kernel to implement a sendmmsg() API similar to recvmmsg() but when I did it I only registered a performance loss due to how cumbersome the interface is actually to use.

The userbase of such an API is pretty limited as if you really want high performance simply move to InfiniBand or use the userspace socket API provided by Solarflare (OpenOnload) or Mellanox that depends upon their 10 GigE RDMA over Ethernet capable interfaces.


That interface doesn't seem to capture your intent, you don't say how many packets are to be generated.

And no, I don't think there is such a call. If the main point of concern is that you want to cut down on the number of userspace to kernel space transitions, I don't know of a better solution.

If you're just annoyed of the structure this gives your application, consider creating a dedicated thread that implements the multi-sending semantics, so your main thread can just hand off a bunch of data with a single call.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号