The unified diff between revisions [43bb367e..] and [6726c07e..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'src/lsi/cmdsocket.c'

#
# old_revision [43bb367e69d2a944206fd7f641ce73111e4bb780]
# new_revision [6726c07e4874e76763555e1476ce427743e8f73c]
#
# patch "src/lsi/cmdsocket.c"
#  from [855bbabd21448d3ac37ff460a412a951df7d226a]
#    to [9b889b4562b843474cf909d9e86a5b7e0ec90a51]
#
============================================================
--- src/lsi/cmdsocket.c	855bbabd21448d3ac37ff460a412a951df7d226a
+++ src/lsi/cmdsocket.c	9b889b4562b843474cf909d9e86a5b7e0ec90a51
@@ -117,7 +117,7 @@ int cmdsocket_accept(void) {
 	}
 
 	cmd_active = c;
-	write(cmd_active, CMDSOCKET_BANNER, sizeof(CMDSOCKET_BANNER));
+	write(cmd_active, CMDSOCKET_BANNER, sizeof(CMDSOCKET_BANNER)-1);
 
 	vm_register_signal_fd(cmd_active, VM_CMDREADQ);
 	vm_wakeup(VM_CMDREADQ);
@@ -130,7 +130,7 @@ void cmd_parse(char *cmd) {
 	char function[CMD_MAXSIZE + PREFIX_MAXSIZE];
 
 	*strchr(cmd, '\n') = '\0';
-	printf("DEBUG: Received command: %s\n", cmd);
+//	printf("DEBUG: Received command: %s\n", cmd);
 	fflush(stdout);
 
 	sp = strtok(cmd, " \t\r");
@@ -143,7 +143,7 @@ void cmd_parse(char *cmd) {
 	strcpy(function, cmd_prefix);
 	strncat(function, cmd, CMD_MAXSIZE);
 
-	printf("DEBUG: function: %s, arg %d\n", function, arg);
+//	printf("DEBUG: function: %s, arg %d\n", function, arg);
 	fflush(stdout);
 	if (vm_spawn_args(function, 1, arg)) {
 		/* Write an ack here, once a proper function exists */
@@ -154,7 +154,7 @@ void cmd_parse(char *cmd) {
 		write(cmd_active, "ERROR\n", strlen("ERROR\n"));
 	}
 
-	printf("Received command: %s\n", cmd);
+//	printf("Received command: %s\n", cmd);
 }
 
 int cmdsocket_read(void)
@@ -202,3 +202,31 @@ int cmdsocket_read(void)
 		}
 	}
 }
+
+/*
+ * Returns offset to restart at. If off == len, then we have finished.
+ * If the return value is the same as off passed in, then the caller
+ * should sleep.
+ */
+int cmdsocket_write(char *buffer, int len, int off)
+{
+//	printf("cmdsocket_write called with %p, %d, %d\n", buffer, len, off);
+	if (!cmdsocket_initialised)
+		return 0;
+	if (!cmd_active)
+		return 0;
+
+	while (off < len) {
+		int r;
+		r = write(cmd_active, buffer + off, len - off);
+		if (r == -1) {
+			if (errno == EAGAIN)
+				return off;
+			warn("error writing packet");
+		}
+		if (r == 0)
+			return off;
+		off += r;
+	}
+	return off;
+}