Skip to content

Commit

Permalink
Prepare mmsghdr structure properly. (#2346)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ser-0xff and Lukasa authored Jan 12, 2023
1 parent 602989b commit c8ec84e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/NIOPosix/PendingDatagramWritesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private func doPendingDatagramWriteVectorOperation(pending: PendingDatagramWrite
msg_control: controlMessageBytePointer.baseAddress,
msg_controllen: .init(controlMessageBytePointer.count),
msg_flags: 0)
msgs[c] = MMsgHdr(msg_hdr: msg, msg_len: CUnsignedInt(toWriteForThisBuffer))
msgs[c] = MMsgHdr(msg_hdr: msg, msg_len: 0)
}
c += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class PendingDatagramWritesManagerTests: XCTestCase {
XCTAssertEqual(expected[multiState].map { numericCast($0.0) }, ptrs.map { $0.msg_hdr.msg_iov.pointee.iov_len },
"in vector write \(multiState) (overall \(everythingState)), \(expected[multiState]) byte counts expected but \(ptrs.map { $0.msg_hdr.msg_iov.pointee.iov_len }) actual",
file: (file), line: line)
XCTAssertEqual(expected[multiState].map { $0.0 }, ptrs.map { Int($0.msg_len) },
XCTAssertEqual(ptrs.map { Int($0.msg_len) }, Array(repeating: 0, count: ptrs.count),
"in vector write \(multiState) (overall \(everythingState)), \(expected[multiState]) byte counts expected but \(ptrs.map { $0.msg_len }) actual",
file: (file), line: line)
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",
Expand Down

0 comments on commit c8ec84e

Please sign in to comment.