Skip to content

Not always correct error checking when sending data via socket #405

@dngrudin

Description

@dngrudin
size_t SocketOutput::DoWrite(const void* data, size_t len) {
#if defined (_linux_)
    static const int flags = MSG_NOSIGNAL;
#else
    static const int flags = 0;
#endif

    if (::send(s_, (const char*)data, (int)len, flags) != (int)len) {
        throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to send " + std::to_string(len) + " bytes of data");
    }

    return len;
}

Hello.
Checking the inequality of the size of the sent data and the size of the input data will not always correctly indicate problems. Sometimes, even for a blocking socket, the send function can return a size smaller than the one passed to the function. And only if the function returned the value -1, this will indicate errors.

Created PR #404 with implementation of change to function return result check. @Enmk Please check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions