Re: recvmmsg() behaviour with MSG_PEEK flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 15, 2022 at 1:03 PM Alexander Babayants
<babayants.alexander@xxxxxxxxx> wrote:
>
> Hello!
>
> The behaviour of recvmmsg() with MSG_PEEK flag confuses me. I'd expect
> it to peek multiple messages at once, but it seems to peek only the
> first one, filling each of the provided struct msghdr with a copy of
> the first message. I do not see if it is documented anywhere, is it a
> bug or intended design?
>
> What I want to achieve is to first peek into the socket, get the size
> of each message, then allocate appropriate buffers and read the
> messages with the second recvmmsg() call. This seems to be a
> relatively common pattern for reading single messages via recvmsg(),
> and I naively expected it to work with recvmmsg() too.
>

MSG_PEEK is a mistake really, it considerably increases the cost of
receiving packets,
because you need twice more system calls.

It also increases costs in the kernel, having to deal with it, even if
not used by fast applications.

Adding proper MSG_PEEK support to recvmmsg() is tricky, do_recvmmsg()
would probably have
to be completely reimplemented to not call ___sys_recvmsg(), or risk
some quadratic behavior
if each ___sys_recvmsg() has to skip over N datagrams



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux