system/FileDescriptor: add method FullWrite()
This commit is contained in:
@@ -298,6 +298,24 @@ FileDescriptor::FullRead(void *_buffer, size_t length)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::FullWrite(const void *_buffer, size_t length)
|
||||
{
|
||||
const uint8_t *buffer = (const uint8_t *)_buffer;
|
||||
|
||||
while (length > 0) {
|
||||
ssize_t nbytes = Write(buffer, length);
|
||||
if (nbytes <= 0) {
|
||||
if (nbytes < 0)
|
||||
throw MakeErrno("Failed to write");
|
||||
throw std::runtime_error("Failed to write");
|
||||
}
|
||||
|
||||
buffer += nbytes;
|
||||
length -= nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
int
|
||||
|
@@ -237,6 +237,12 @@ public:
|
||||
return ::write(fd, buffer, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write until all of the given buffer has been written.
|
||||
* Throws on error.
|
||||
*/
|
||||
void FullWrite(const void *buffer, size_t length);
|
||||
|
||||
#ifndef _WIN32
|
||||
int Poll(short events, int timeout) const noexcept;
|
||||
|
||||
|
Reference in New Issue
Block a user