From: Peter Senna Tschudin <peter.senna@linux.intel.com>
To: "igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>
Subject: RFC: Do we want a new igt_write() function?
Date: Mon, 20 Jan 2025 14:39:16 +0100 [thread overview]
Message-ID: <64b1ae2e-e096-4da5-8233-2669bbd816be@linux.intel.com> (raw)
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
reply other threads:[~2025-01-20 13:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=64b1ae2e-e096-4da5-8233-2669bbd816be@linux.intel.com \
--to=peter.senna@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox