From f0191939521e8f2e20a5ae671dd4bee01778a481 Mon Sep 17 00:00:00 2001 From: phani Date: Tue, 24 Dec 2019 17:19:01 -0500 Subject: [PATCH] read() to read from request body! --- runtime/include/types.h | 2 +- runtime/src/libc/uvio.c | 14 +++++++++++++- runtime/tests/Makefile | 3 ++- runtime/tests/empty/main.c | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/runtime/include/types.h b/runtime/include/types.h index 72c6c76..d33e681 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -153,7 +153,7 @@ typedef enum { #define MOD_REQ_RESP_DEFAULT (PAGE_SIZE) #define QUIESCENSE_TIME (1<<20) //cycles! -#define HTTP_HEADERS_MAX 4 +#define HTTP_HEADERS_MAX 6 #define HTTP_HEADER_MAXSZ 32 #define HTTP_HEADERVAL_MAXSZ 64 diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index c834d0c..aa4d314 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -63,8 +63,20 @@ u32 wasm_read(i32 filedes, i32 buf_offset, i32 nbyte) { if (filedes == 0) { +#ifdef STANDALONE char* buf = get_memory_ptr_void(buf_offset, nbyte); return read(filedes, buf, nbyte); +#else + // TODO: multiple reads! + char* buf = get_memory_ptr_void(buf_offset, nbyte); + struct sandbox *s = sandbox_current(); + struct http_request *r = &s->rqi; + if (r->bodylen <= 0) return 0; + int l = nbyte > r->bodylen ? r->bodylen : nbyte; + memcpy(buf, r->body, l); + r->bodylen -= l; + return l; +#endif } int f = io_handle_fd(filedes); // TODO: read on other file types @@ -460,7 +472,7 @@ wasm_readv(i32 fd, i32 iov_offset, i32 iovcnt) struct http_request *r = &s->rqi; if (r->bodylen <= 0) return 0; for (int i = 0; i < iovcnt; i++) { - int l = iov[i].len > r->body_len ? r->body_len : iov[i].len; + int l = iov[i].len > r->bodylen ? r->bodylen : iov[i].len; if (l <= 0) break; char *b = get_memory_ptr_void(iov[i].base_offset, iov[i].len); //http request body! diff --git a/runtime/tests/Makefile b/runtime/tests/Makefile index ea04b66..6f15fbb 100644 --- a/runtime/tests/Makefile +++ b/runtime/tests/Makefile @@ -2,7 +2,8 @@ include Makefile.inc BENCH_DIR=../../silverfish/code_benches/ -TESTS=forever filesys sockserver sockclient empty +TESTS=empty +#TESTS=forever filesys sockserver sockclient empty TESTSRT=$(TESTS:%=%_rt) BENCHES=adpcm basic_math binarytrees bitcount blowfish crc dijkstra fft function_pointers \ gsm libjpeg mandelbrot patricia pgp qsort rsynth sha sqlite stringsearch susan diff --git a/runtime/tests/empty/main.c b/runtime/tests/empty/main.c index bda853b..7a57e3f 100644 --- a/runtime/tests/empty/main.c +++ b/runtime/tests/empty/main.c @@ -6,5 +6,8 @@ int main(int argc, char **argv) { printf("hello\n"); +// char d[16] = { 0 }; +// int r = read(0, d, 15); +// printf("hello [%s]\n", d); return 0; }