The unified diff between revisions [43bb367e..] and [63fe9cf9..] is displayed below. It can also be downloaded as a raw diff.
# # old_revision [43bb367e69d2a944206fd7f641ce73111e4bb780] # new_revision [63fe9cf91eccf15b977d5be7600ee10a17d08d95] # # patch "src/lsi/abi.h" # from [2f5c3543b8ced2defbc5a1bea94b29392c7ee5b1] # to [f5ff3bd7144f8020da012ea0158aa51d862f888e] # # patch "src/lsi/abispec" # from [bf8a0325aba2e8dd563c0c9dc0358989f130e20d] # to [e8cad560a662c1abc9da835eedd7dddafa77d03f] # # patch "src/lsi/cmdsocket.c" # from [855bbabd21448d3ac37ff460a412a951df7d226a] # to [a6b79ffd22f3df90c3d7cca971192dadbfa3e7bb] # # patch "src/lsi/cmdsocket.h" # from [dd5bddfcec81de17a358ae36f8e2626e68430728] # to [9186381827faf9810730c102029aed69109c659e] # # patch "src/lsi/vm.c" # from [f74e79e92252eafbcbc81d3ee4ca5e2e3c79f4a9] # to [0d1a3539301653c5f5cad4792072a3f87ee17d29] # # patch "src/lsi/vm.h" # from [4e84a410186bc2516c890aaedd6b6c3705d1f30a] # to [81ad4a5acde3eb1f6575f48f32a3f1fabb5ba740] # ============================================================ --- src/lsi/abi.h 2f5c3543b8ced2defbc5a1bea94b29392c7ee5b1 +++ src/lsi/abi.h f5ff3bd7144f8020da012ea0158aa51d862f888e @@ -47,4 +47,5 @@ int vm_intfn_cmdsocket_read(void); int vm_intfn_cmdsocket_listen(void); int vm_intfn_cmdsocket_accept(void); int vm_intfn_cmdsocket_read(void); +int vm_intfn_cmdsocket_write(void); int vm_intfn_cmdsocket_prefix(void); ============================================================ --- src/lsi/abispec bf8a0325aba2e8dd563c0c9dc0358989f130e20d +++ src/lsi/abispec e8cad560a662c1abc9da835eedd7dddafa77d03f @@ -36,6 +36,7 @@ function cmdsocket_read function cmdsocket_listen function cmdsocket_accept function cmdsocket_read +function cmdsocket_write function cmdsocket_prefix /* ============================================================ --- src/lsi/cmdsocket.c 855bbabd21448d3ac37ff460a412a951df7d226a +++ src/lsi/cmdsocket.c a6b79ffd22f3df90c3d7cca971192dadbfa3e7bb @@ -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; +} ============================================================ --- src/lsi/cmdsocket.h dd5bddfcec81de17a358ae36f8e2626e68430728 +++ src/lsi/cmdsocket.h 9186381827faf9810730c102029aed69109c659e @@ -5,4 +5,5 @@ int cmdsocket_read(void); int cmdsocket_listen(int port); int cmdsocket_accept(void); int cmdsocket_read(void); +int cmdsocket_write(char *buffer, int len, int off); int cmdsocket_prefix(char *); ============================================================ --- src/lsi/vm.c f74e79e92252eafbcbc81d3ee4ca5e2e3c79f4a9 +++ src/lsi/vm.c 0d1a3539301653c5f5cad4792072a3f87ee17d29 @@ -464,6 +464,24 @@ int vm_intfn_cmdsocket_read(void) return 1; } +int vm_intfn_cmdsocket_write(void) +{ + int off = stack_get(vm_current, 1); + int len = stack_get(vm_current, 2); + char *buffer = stack_getstr(vm_current, len, 2); + int newoff; + + newoff = cmdsocket_write(buffer, len, off); + stack_poke(vm_current, 1, newoff); + + if (newoff != len) { + vm_queue(vm_current, VM_CMDWRITEQ); + vm_current = NULL; + return 0; + } + return 1; +} + int vm_intfn_beatdetect_read(void) { if (!beatdetect_read()) { ============================================================ --- src/lsi/vm.h 4e84a410186bc2516c890aaedd6b6c3705d1f30a +++ src/lsi/vm.h 81ad4a5acde3eb1f6575f48f32a3f1fabb5ba740 @@ -18,6 +18,7 @@ void vm_wakeup(int queue); #define VM_MIDIQ 8 #define VM_CMDLISTENQ 9 #define VM_CMDREADQ 10 +#define VM_CMDWRITEQ 20 #define VM_USERQMIN 20 #define VM_NOQUEUE (-1)