Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining sento() write writev()?

I've set a udp socket and call sendto() with a different recipient at each call.

I would like to use writev() in order to benefit scater/gather io but writev() does not allows me to specify the recipient addr/port as in sendto(). Any suggestions?

like image 782
yves Baumes Avatar asked Aug 04 '26 21:08

yves Baumes


1 Answers

On Linux, there is sendmmsg(2)

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. (This has performance benefits for some applications.)

The prototype is:

int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
             unsigned int flags);

struct mmsghdr {
    struct msghdr msg_hdr;  /* Message header */
    unsigned int  msg_len;  /* Number of bytes transmitted */
};

Since both the address and the i/o vector is specified in struct msghdr, you can both send to multiple destinations and make use of scatter/gather.

like image 184
wkz Avatar answered Aug 07 '26 08:08

wkz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!