From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v3 04/10] chardev/char: Document qemu_chr_write[_all]()
Date: Wed, 12 Nov 2025 14:41:37 +0100 [thread overview]
Message-ID: <20251112134143.27194-5-philmd@linaro.org> (raw)
In-Reply-To: <20251112134143.27194-1-philmd@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/chardev/char.h | 29 +++++++++++++++++++++++++++++
chardev/char.c | 1 +
2 files changed, 30 insertions(+)
diff --git a/include/chardev/char.h b/include/chardev/char.h
index df55c7f4e67..4aab018938d 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -223,8 +223,37 @@ void qemu_chr_set_feature(Chardev *chr,
ChardevFeature feature);
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
bool permit_mux_mon);
+
+/**
+ * qemu_chr_write: Write data to a character backend
+ * @s: the character backend to write to
+ * @buf: the data
+ * @len: the number of bytes to write
+ * @write_all: whether to block until all chars are written
+ *
+ * Attempt to write all the data to the backend. If not all
+ * data can be consumed and @write_all is %true, keep retrying
+ * while the backend return EAGAIN, effectively blocking the caller.
+ *
+ * Returns: the number of bytes consumed or -1 on error.
+ * On error, %errno is also set as appropriate.
+ */
int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all);
+
+/**
+ * qemu_chr_write_all: Write data to a character backend
+ * @s: the character backend to write to
+ * @buf: the data
+ * @len: the number of bytes to write
+ *
+ * Unlike @qemu_chr_write, this call will block if the backend
+ * cannot consume all of the data attempted to be written.
+ *
+ * Returns: the number of bytes consumed or -1 on error.
+ * On error, %errno is also set as appropriate.
+ */
#define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
+
int qemu_chr_wait_connected(Chardev *chr, Error **errp);
#define TYPE_CHARDEV "chardev"
diff --git a/chardev/char.c b/chardev/char.c
index 3e432195a5a..105b0d53184 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -108,6 +108,7 @@ static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
}
}
+/* qemu_chr_write_buffer: Return the number of bytes consumed or -1 on error. */
static int qemu_chr_write_buffer(Chardev *s,
const uint8_t *buf, int len,
int *offset, bool write_all)
--
2.51.0
next prev parent reply other threads:[~2025-11-12 13:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 13:41 [PATCH v3 00/10] chardev: Improve @docstring and clarify qemu_chr_write() uses Philippe Mathieu-Daudé
2025-11-12 13:41 ` [PATCH v3 01/10] chardev/char-fe: Improve @docstrings Philippe Mathieu-Daudé
2025-11-12 13:58 ` Daniel P. Berrangé
2025-11-13 11:31 ` Marc-André Lureau
2025-11-12 13:41 ` [PATCH v3 02/10] chardev/char-io: Add @docstrings for io_channel_send[_full]() Philippe Mathieu-Daudé
2025-11-13 11:32 ` Marc-André Lureau
2025-11-12 13:41 ` [PATCH v3 03/10] chardev/char: Improve ChardevClass::chr_write() docstring Philippe Mathieu-Daudé
2025-11-12 13:41 ` Philippe Mathieu-Daudé [this message]
2025-11-12 13:41 ` [PATCH v3 05/10] chardev/char-pty: Do not ignore chr_write() failures Philippe Mathieu-Daudé
2025-11-12 13:41 ` [PATCH v3 06/10] chardev/char: Allow partial writes in qemu_chr_write() Philippe Mathieu-Daudé
2025-11-13 11:30 ` Marc-André Lureau
2025-11-12 13:41 ` [PATCH v3 07/10] chardev/char: Preserve %errno " Philippe Mathieu-Daudé
2025-11-12 13:41 ` [PATCH v3 08/10] chardev/char: Document qemu_chr_fe_write()'s return value Philippe Mathieu-Daudé
2025-11-13 11:32 ` Marc-André Lureau
2025-11-12 13:41 ` [PATCH v3 09/10] hw/char: Simplify when qemu_chr_fe_write() could not write Philippe Mathieu-Daudé
2025-11-12 13:41 ` [PATCH v3 10/10] system/replay: Rename some method parameters Philippe Mathieu-Daudé
2025-11-12 13:44 ` [PATCH v3 00/10] chardev: Improve @docstring and clarify qemu_chr_write() uses Philippe Mathieu-Daudé
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=20251112134143.27194-5-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).