mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibCore: Handle partial writes in Socket::send()
Right now Socket::send() assumes that it can send everything in one go. However, send() is allowed to do partial writes and while that can't happen at the moment there's nothing that says this can't happen in the future (like in the next commit).
This commit is contained in:
parent
a428812ba2
commit
dce97678ae
Notes:
sideshowbarker
2024-07-18 17:23:48 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/dce97678ae4 Pull-request: https://github.com/SerenityOS/serenity/pull/7466
|
@ -158,12 +158,15 @@ ByteBuffer Socket::receive(int max_size)
|
|||
|
||||
bool Socket::send(ReadonlyBytes data)
|
||||
{
|
||||
ssize_t nsent = ::send(fd(), data.data(), data.size(), 0);
|
||||
if (nsent < 0) {
|
||||
set_error(errno);
|
||||
return false;
|
||||
auto remaining_bytes = data.size();
|
||||
while (remaining_bytes > 0) {
|
||||
ssize_t nsent = ::send(fd(), data.data() + (data.size() - remaining_bytes), remaining_bytes, 0);
|
||||
if (nsent < 0) {
|
||||
set_error(errno);
|
||||
return false;
|
||||
}
|
||||
remaining_bytes -= nsent;
|
||||
}
|
||||
VERIFY(static_cast<size_t>(nsent) == data.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue