Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving multiple datagrams in a single system call

On Linux, unless I'm mistaken, an application can use the socket call family to send or receive one packet at a time on datagram transports.

Would like to know if Linux provides a means for the application to send and receive multiple packets in a single call on datagram transports.

like image 239
Maddy Avatar asked Jul 17 '13 13:07

Maddy


1 Answers

Use recvmmsg to receive multiple datagram packets (example UDP)

int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
                    unsigned int flags, struct timespec *timeout);
DESCRIPTION         
   The recvmmsg() system call is an extension of recvmsg(2) that allows
   the caller to receive multiple messages from a socket using a single
   system call. ...

http://man7.org/linux/man-pages/man2/recvmmsg.2.html

Use sendmmsg to send...

int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
                    unsigned int flags);
DESCRIPTION        
   The sendmmsg() system call is an extension of sendmsg(2) that allows
   the caller to transmit multiple messages on a socket using a single
   system call.

http://man7.org/linux/man-pages/man2/sendmmsg.2.html

like image 134
Gabe Avatar answered Sep 22 '22 21:09

Gabe