aboutsummaryrefslogtreecommitdiff
path: root/src/micro/port_wasm_stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/micro/port_wasm_stream.c')
-rw-r--r--src/micro/port_wasm_stream.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/micro/port_wasm_stream.c b/src/micro/port_wasm_stream.c
index 155cde4..d96ceab 100644
--- a/src/micro/port_wasm_stream.c
+++ b/src/micro/port_wasm_stream.c
@@ -17,7 +17,7 @@ extern void js_msg(int c);
static unsigned char chunk[CHUNK];
/* the input the server has not read yet: q[qp..qn) */
static unsigned char q[QCAP];
-static int qn, qp, closed;
+static int qn, qp, closed, polled;
unsigned char *wasm_chunk(void) { return chunk; }
int wasm_chunk_cap(void) { return (int)sizeof chunk; }
@@ -38,6 +38,10 @@ int wasm_feed(int n)
return 0;
}
+/* 1 while the server is suspended by a poll rather than by a read: the host should resume it
+ after the event loop has run, whether or not input came */
+int wasm_polling(void) { return polled; }
+
/* no more input will come: the next read past the end is -1 */
void wasm_close(void) { closed = 1; }
@@ -83,6 +87,10 @@ Cell micro_syscall(Cell *mem, Cell op, Cell a, Cell b, Cell c)
if (a == 2) return HEAP_HI;
if (a == 3) return (Cell)micro_mem_words() * 8;
return -1;
+ case 42: /* poll: suspend once so the host can feed what has arrived, then say if input is waiting */
+ if (!polled) { polled = 1; return MICRO_WAIT; }
+ polled = 0;
+ return qp < qn;
case 7: /* exit: the run ends */
return -1;
case 21: /* argc: the server has no command line of its own, so <eval> alone */