[lxc-devel] [patch] batched reads for lxc_console

Michael Tokarev mjt at tls.msk.ru
Sat Nov 14 15:36:11 UTC 2009


Instead of doing I/O one-byte-at-a-time in lxc_console,
which is slow, let's do it in batches.  Only for output
(from container to the host system), since input is most
likely one-byte-at-a-time anyway (from a keyboard).

Signed-Off-By: Michael Tokarev <mjt at tls.msk.ru>

diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c
index b662572..4afcfa7 100644
--- a/src/lxc/lxc_console.c
+++ b/src/lxc/lxc_console.c
@@ -123,7 +123,6 @@ int main(int argc, char *argv[])
 
 	/* let's proxy the tty */
 	for (;;) {
-		char c;
 		struct pollfd pfd[2] = {
 			{ .fd = 0,
 			  .events = POLLIN|POLLPRI,
@@ -143,6 +142,7 @@ int main(int argc, char *argv[])
 		/* read the "stdin" and write that to the master
 		 */
 		if (pfd[0].revents & POLLIN) {
+			char c;
 			if (read(0, &c, 1) < 0) {
 				SYSERROR("failed to read");
 				goto out_err;
@@ -170,12 +170,14 @@ int main(int argc, char *argv[])
 
 		/* read the master and write to "stdout" */
 		if (pfd[1].revents & POLLIN) {
-			if (read(master, &c, 1) < 0) {
+			char buf[1024];
+			int r;
+			r = read(master, buf, sizeof(buf));
+			if (r < 0) {
 				SYSERROR("failed to read");
 				goto out_err;
 			}
-			printf("%c", c);
-			fflush(stdout);
+			write(1, buf, r);
 		}
 	}
 out:




More information about the lxc-devel mailing list