wsd: log: retry on write failure and flush
Change-Id: I7417a74959a52e2a079bfe4502ed238d1517ea60 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
56fd825187
commit
a00fbae7c5
1 changed files with 20 additions and 2 deletions
|
@ -42,10 +42,28 @@ namespace Log
|
|||
static constexpr std::size_t BufferSize = 64 * 1024;
|
||||
|
||||
public:
|
||||
void close() override { flush(); }
|
||||
|
||||
/// Write the given buffer to stderr directly.
|
||||
static inline bool writeRaw(const char* data, std::size_t size)
|
||||
static inline int writeRaw(const char* data, std::size_t size)
|
||||
{
|
||||
return ::write(STDERR_FILENO, data, size) == static_cast<ssize_t>(size);
|
||||
std::size_t i = 0;
|
||||
for (; i < size;)
|
||||
{
|
||||
int wrote;
|
||||
while ((wrote = ::write(STDERR_FILENO, data + i, size - i)) < 0 && errno == EINTR)
|
||||
{
|
||||
}
|
||||
|
||||
if (wrote < 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
i += wrote;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
template <std::size_t N> inline void writeRaw(const char (&data)[N])
|
||||
|
|
Loading…
Reference in a new issue