From 766f4c0280dbb6bb3f9ed0f1a29e33903de7fc61 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Thu, 6 Feb 2020 03:07:46 +0800 Subject: [PATCH] udp: Fix mmsghdr struct initializer for Musl On OpenWrt x64 there are paddings fields in the struct, making the initializer list not work. --- src/net/socket/udp_socket_posix.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net/socket/udp_socket_posix.cc b/src/net/socket/udp_socket_posix.cc index 63ae4274d1..55eb5748f8 100644 --- a/src/net/socket/udp_socket_posix.cc +++ b/src/net/socket/udp_socket_posix.cc @@ -1156,8 +1156,12 @@ SendResult UDPSocketPosixSender::InternalSendmmsgBuffers( for (auto& buffer : buffers) msg_iov->push_back({const_cast(buffer->data()), buffer->length()}); msgvec->reserve(buffers.size()); - for (size_t j = 0; j < buffers.size(); j++) - msgvec->push_back({{nullptr, 0, &msg_iov[j], 1, nullptr, 0, 0}, 0}); + for (size_t j = 0; j < buffers.size(); j++) { + struct mmsghdr hdr = {}; + hdr.msg_hdr.msg_iov = &msg_iov[j]; + hdr.msg_hdr.msg_iovlen = 1; + msgvec->push_back(hdr); + } int result = HANDLE_EINTR(Sendmmsg(fd, &msgvec[0], buffers.size(), 0)); SendResult send_result(0, 0, std::move(buffers)); if (result < 0) {