Implement streams IPC mechanism
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m47s

This commit is contained in:
2026-03-18 22:27:56 +01:00
parent 77ab25bcee
commit 80a728f04b
22 changed files with 311 additions and 50 deletions

View File

@@ -9,7 +9,7 @@ $(eval $(call add_lib,libterminal))
$(eval $(call add_lib,libfat))
$(eval $(call add_lib,libmalloc))
$(eval $(call add_lib,libdebugconsole))
$(eval $(call add_lib,libkb))
$(eval $(call add_include,libkb))
cflags += -DPRINTF_INCLUDE_CONFIG_H=1

View File

@@ -14,6 +14,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <streams.h>
#include <string.h>
#include <system.h>
#include <tcursor.h>
@@ -77,10 +78,12 @@ void app_main (void) {
mprintf (PROMPT);
for (;;) {
int ch = kb_read_key ();
uint8_t ch;
if (ch == 0)
if (stream_read (process_get_pgid (), STREAM_IN, &ch, 1) <= 0) {
sched ();
continue;
}
if (ch == '\n')
break;

View File

@@ -14,6 +14,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <streams.h>
#include <string.h>
#include <system.h>
#include <tcursor.h>
@@ -231,10 +232,15 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
(int)(editor.cursor.line - editor.row_offset) + 1,
(int)(editor.cursor.col - editor.col_offset) + 1 + (int)gutter_width);
mail_send (process_get_exec_pgid (), backbuffer, bbptr - backbuffer);
stream_write (process_get_pgid (), STREAM_OUT, backbuffer, bbptr - backbuffer);
uint8_t ch = 0;
mail_receive (&ch, 1);
for (;;) {
if (stream_read (process_get_pgid (), STREAM_IN, &ch, 1) > 0)
break;
else
sched ();
}
switch (ch) {
case '\b':

View File

@@ -18,6 +18,7 @@
#include <process_self.h>
#include <stddef.h>
#include <str_status.h>
#include <streams.h>
#include <string.h>
#include <system.h>
#include <tcursor.h>
@@ -160,7 +161,7 @@ static void cat (struct context* context, char** file_paths, size_t files_count)
return;
}
mail_send (process_get_exec_pgid (), buffer, chunk_size);
stream_write (process_get_pgid (), STREAM_OUT, buffer, chunk_size);
}
if (rem > 0) {
@@ -170,7 +171,7 @@ static void cat (struct context* context, char** file_paths, size_t files_count)
return;
}
mail_send (process_get_exec_pgid (), buffer, rem);
stream_write (process_get_pgid (), STREAM_OUT, buffer, rem);
}
filereader_fini (&fr);
@@ -339,37 +340,37 @@ static void help (struct context* context) {
cprintf (context, "quit\n");
}
static void cmd_cancel_proc (void* arg) {
int pid = (int)(uintptr_t)arg;
/* static void cmd_cancel_proc (void* arg) { */
/* int pid = (int)(uintptr_t)arg; */
int ch = 0;
/* int ch = 0; */
for (;;) {
ch = kb_read_key_nonblock ();
/* for (;;) { */
/* ch = kb_read_key_nonblock (); */
if (ch == KB_CTRL ('C'))
break;
else
sched ();
}
/* if (ch == KB_CTRL ('C')) */
/* break; */
/* else */
/* sched (); */
/* } */
kill (pid);
}
/* kill (pid); */
/* } */
static void cmd_collect_proc (void* arg) {
#define RECV_MAX (1024 * 16)
/* static void cmd_collect_proc (void* arg) { */
/* #define RECV_MAX (1024 * 16) */
(void)arg;
/* (void)arg; */
char recv[RECV_MAX];
for (;;) {
memset (recv, 0, sizeof (recv));
if (mail_receive_nonblock (&recv, sizeof (recv) - 1) == ST_OK)
mail_send (process_get_exec_pgid (), recv, strlen (recv));
else
sched ();
}
}
/* char recv[RECV_MAX]; */
/* for (;;) { */
/* memset (recv, 0, sizeof (recv)); */
/* if (mail_receive_nonblock (&recv, sizeof (recv) - 1) == ST_OK) */
/* mail_send (process_get_exec_pgid (), recv, strlen (recv)); */
/* else */
/* sched (); */
/* } */
/* } */
static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
if (strcmp (cmd->name, "echo") == 0) {
@@ -442,16 +443,16 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
}
}
struct process_data* collect_pdata = process_spawn (&cmd_collect_proc, NULL);
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, (void*)pid);
/* struct process_data* collect_pdata = process_spawn (&cmd_collect_proc, NULL); */
/* struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, (void*)pid); */
exec_partial_fini (pid);
wait_for_pid (pid);
kill (collect_pdata->pid);
process_data_free (collect_pdata);
kill (cancel_pdata->pid);
process_data_free (cancel_pdata);
/* kill (collect_pdata->pid); */
/* process_data_free (collect_pdata); */
/* kill (cancel_pdata->pid); */
/* process_data_free (cancel_pdata); */
}
}