套接字发送的MSG_WAITALL得到22 EINVAL

问题描述 投票:0回答:1
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);
}

我正在尝试创建具有指定大小的发送函数,该函数发送所有数据。为什么send引发EINVAL错误?什么参数无效?

c++ sockets posix
1个回答
2
投票

什么参数无效?

send功能没有MSG_WAITALL选项。因此MSG_WAITALL无效。

send仅支持:

  • MSG_EOR
  • MSG_OOB

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

© www.soinside.com 2019 - 2024. All rights reserved.