Search code examples
c++socketsposix

Socket send with MSG_WAITALL got 22 EINVAL


bool AbstractSocket::send(void *data, const size_t &size)
{
    ssize_t result = ::send(m_sfd, data, size, MSG_WAITALL);
    if (result == -1 ) {
        if (errno != EAGAIN) {
            LOG_ERR("failed to write socket")
            emitErrorSignal();
        } else { // else If errno == EAGAIN
            // that means we have read all data.
            return true;
        }
    } else if (result == 0) {
        // The remote has closed the connection
        LOG_WNG("the remote has closed the connection")
        emitErrorSignal(std::errc::connection_aborted);
    }
    return size == static_cast<size_t>(result);
}

I am trying to create a send function with specified size which sends all the data. Why send raise EINVAL error? What argument is invalid?


Solution

  • What argument is invalid?

    send function does not have the MSG_WAITALL option. So MSG_WAITALL is invalid.

    send only support:

    • MSG_EOR
    • MSG_OOB

    https://linux.die.net/man/3/send