[PATCH] Receive multiple packets at a time

Michael Tokarev
Thu, 10 Dec 2015 06:34:45 -0000

10.12.2015 09:20, Michael Tokarev wrote:
> 10.12.2015 03:35, Samuel Thibault wrote:
> []
>
> I suggest reducing ifdeffery in handle_incoming_vpn_data(), especially
> the error checking code.
>
> The function isn't that large now, it might be much better to have
> two different implementations.  Like this (untested, patch attached):
>
> void handle_incoming_vpn_data(int sock) {
>
> #ifdef HAVE_RECVMMSG
> #define MAX_MSG  256
>
>         vpn_packet_t pkt[MAX_MSG];
>         sockaddr_t from[MAX_MSG];
>         struct mmsghdr msg[MAX_MSG];
>         struct iovec iov[MAX_MSG];
>         int num = 1, i;
>
>         for(i = 0; i < MAX_MSG; i++)
>         {
>                 msg[i].msg_hdr.msg_name = &from[i].sa;
>                 msg[i].msg_hdr.msg_namelen = sizeof(from[i]);
>                 iov[i].iov_base = &pkt[i].seqno;
>                 iov[i].iov_len = MAXSIZE;
>                 msg[i].msg_hdr.msg_iov = &iov[i];
>                 msg[i].msg_hdr.msg_iovlen = 1;
>                 msg[i].msg_hdr.msg_control = NULL;
>                 msg[i].msg_hdr.msg_controllen = 0;
>         }

Also, this is interesting.  We should either reduce MAX_MSG to, say, 64,
or even 16, and/or initialize this array statically (except of iov.iov_len).
There's just too much work doing on each step, and it is highly unlikely
we'll have 256 packets in queue to process.

Thanks,

/mjt