Skip to content

Commit c8ec84e

Browse files
ser-0xffLukasa
andauthored
Prepare mmsghdr structure properly. (#2346)
Motivation: According to the Linux man page the msg_len field supposed to be used to return a number of bytes sent for the particular message. It does not make a sense to initialize it with a size of the message. Modifications: Change msg_leg field initialization, use 0 instead of message size. Result: Use sendmmsg() call properly. Co-authored-by: Cory Benfield <[email protected]>
1 parent 602989b commit c8ec84e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Sources/NIOPosix/PendingDatagramWritesManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private func doPendingDatagramWriteVectorOperation(pending: PendingDatagramWrite
139139
msg_control: controlMessageBytePointer.baseAddress,
140140
msg_controllen: .init(controlMessageBytePointer.count),
141141
msg_flags: 0)
142-
msgs[c] = MMsgHdr(msg_hdr: msg, msg_len: CUnsignedInt(toWriteForThisBuffer))
142+
msgs[c] = MMsgHdr(msg_hdr: msg, msg_len: 0)
143143
}
144144
c += 1
145145
}

Tests/NIOPosixTests/PendingDatagramWritesManagerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class PendingDatagramWritesManagerTests: XCTestCase {
155155
XCTAssertEqual(expected[multiState].map { numericCast($0.0) }, ptrs.map { $0.msg_hdr.msg_iov.pointee.iov_len },
156156
"in vector write \(multiState) (overall \(everythingState)), \(expected[multiState]) byte counts expected but \(ptrs.map { $0.msg_hdr.msg_iov.pointee.iov_len }) actual",
157157
file: (file), line: line)
158-
XCTAssertEqual(expected[multiState].map { $0.0 }, ptrs.map { Int($0.msg_len) },
158+
XCTAssertEqual(ptrs.map { Int($0.msg_len) }, Array(repeating: 0, count: ptrs.count),
159159
"in vector write \(multiState) (overall \(everythingState)), \(expected[multiState]) byte counts expected but \(ptrs.map { $0.msg_len }) actual",
160160
file: (file), line: line)
161161
XCTAssertEqual(expected[multiState].map { $0.1 }, ptrs.map { SocketAddress($0.msg_hdr.msg_name.assumingMemoryBound(to: sockaddr.self)) }, "in vector write \(multiState) (overall \(everythingState)), \(expected[multiState].map { $0.1 }) addresses expected but \(ptrs.map { SocketAddress($0.msg_hdr.msg_name.assumingMemoryBound(to: sockaddr.self)) }) actual",

0 commit comments

Comments
 (0)