func sendmsg()

in Sources/NIOPosix/Socket.swift [168:203]


    func sendmsg(pointer: UnsafeRawBufferPointer,
                 destinationPtr: UnsafePointer<sockaddr>,
                 destinationSize: socklen_t,
                 controlBytes: UnsafeMutableRawBufferPointer) throws -> IOResult<Int> {
        // Dubious const casts - it should be OK as there is no reason why this should get mutated
        // just bad const declaration below us.
        var vec = iovec(iov_base: UnsafeMutableRawPointer(mutating: pointer.baseAddress!), iov_len: numericCast(pointer.count))
        let notConstCorrectDestinationPtr = UnsafeMutableRawPointer(mutating: destinationPtr)

        return try withUnsafeHandle { handle in
            return try withUnsafeMutablePointer(to: &vec) { vecPtr in
#if os(Windows)
                var messageHeader =
                    WSAMSG(name: notConstCorrectDestinationPtr
                                    .assumingMemoryBound(to: sockaddr.self),
                           namelen: destinationSize,
                           lpBuffers: vecPtr,
                           dwBufferCount: 1,
                           Control: WSABUF(len: ULONG(controlBytes.count),
                                           buf: controlBytes.baseAddress?
                                                    .bindMemory(to: CHAR.self,
                                                                capacity: controlBytes.count)),
                           dwFlags: 0)
#else
                var messageHeader = msghdr(msg_name: notConstCorrectDestinationPtr,
                                           msg_namelen: destinationSize,
                                           msg_iov: vecPtr,
                                           msg_iovlen: 1,
                                           msg_control: controlBytes.baseAddress,
                                           msg_controllen: .init(controlBytes.count),
                                           msg_flags: 0)
#endif
                return try NIOBSDSocket.sendmsg(socket: handle, msgHdr: &messageHeader, flags: 0)
            }
        }
    }