Split IO handling code into separate handler modules
Currently, we have a direct, explicit link between the VUART IO and the
"outbound" data, currently to stdio.
We'll want to do multiple things with the VUART data in future (eg.,
logging).
This change introduces "handlers"; a struct of callbacks that are
invoked when UART data is available, or when a (handler-provided) poll
descriptor returns new events. We convert the stdio code into a handler
as part of this.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..11f6090
--- /dev/null
+++ b/util.c
@@ -0,0 +1,23 @@
+
+
+#include <err.h>
+#include <unistd.h>
+
+#include "console-server.h"
+
+int write_buf_to_fd(int fd, const uint8_t *buf, size_t len)
+{
+ size_t pos;
+ ssize_t rc;
+
+ for (pos = 0; pos < len; pos += rc) {
+ rc = write(fd, buf + pos, len - pos);
+ if (rc <= 0) {
+ warn("Write error");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+