Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
dngrudin opened this issue Dec 13, 2024 · 2 comments
Closed

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

dngrudin opened this issue Dec 13, 2024 · 2 comments

Comments

@dngrudin
Copy link
Contributor

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.

@Enmk
Copy link
Collaborator

Enmk commented Dec 16, 2024

Resolved by #404

@Enmk Enmk closed this as completed Dec 16, 2024
@dngrudin
Copy link
Contributor Author

@Enmk didn’t immediately see that there are cases when it is necessary to implement re-sending of data. Created another PR #407 with the implementation of resending when performing a flash on a buffered output.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants