* RFC: Do we want a new igt_write() function?
@ 2025-01-20 13:39 Peter Senna Tschudin
0 siblings, 0 replies; only message in thread
From: Peter Senna Tschudin @ 2025-01-20 13:39 UTC (permalink / raw)
To: igt-dev@lists.freedesktop.org
Dear List,
I find myself wanting to repeat some small variation of a write function
that retries on recoverable errors and that aborts on unrecoverable errors.
Is the idea of an igt_write() function a welcome addition to lib/igt_core?
Something like:
#define MAX_WRITE_RETRIES 5
/**
* igt_write - Writes the buffer to the file descriptor retrying when possible.
* @fd: The file descriptor to write to.
* @buf: Pointer to the data to write.
* @count: Total number of bytes to write.
*
* Returns the total number of bytes written on success, or -1 on failure.
*/
ssize_t igt_write(int fd, const void *buf, size_t count) {
const char *ptr = buf;
size_t remaining = count;
ssize_t written;
int retries = 0;
while (remaining > 0) {
written = write(fd, ptr, remaining);
if (written > 0) {
ptr += written;
remaining -= written;
} else if (written == -1) {
if (errno == EINTR || errno == EAGAIN) {
/* Retry for recoverable errors */
if (++retries > MAX_WRITE_RETRIES) {
igt_err("igt_write: Exceeded retry limit\n");
return -1;
}
continue;
} else {
/* Log unrecoverable error */
igt_err("igt_write: unrecoverable write error");
return -1;
}
}
}
return count;
}
Thanks,
Peter
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-01-20 13:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 13:39 RFC: Do we want a new igt_write() function? Peter Senna Tschudin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox