int CNIODarwin_sendmmsg()

in Sources/CNIODarwin/shim.c [24:49]


int CNIODarwin_sendmmsg(int sockfd, CNIODarwin_mmsghdr *msgvec, unsigned int vlen, int flags) {
    // Some quick error checking. If vlen can't fit into int, we bail.
    if ((vlen > INT_MAX) || (msgvec == NULL)) {
        errno = EINVAL;
        return -1;
    }

    for (unsigned int i = 0; i < vlen; i++) {
        ssize_t sendAmount = sendmsg(sockfd, &(msgvec[i].msg_hdr), flags);
        if (sendAmount < 0 && i == 0) {
            // Error on the first send, return the error.
            return -1;
        }

        if (sendAmount < 0) {
            // Error on a later send, return short.
            return i;
        }

        // Send succeeded, save off the bytes written.
        msgvec[i].msg_len = (unsigned int)sendAmount;
    }

    // If we dropped out, we sent everything.
    return vlen;
}