read() to read from request body!

main
phani 5 years ago
parent 2e8a22b710
commit f019193952

@ -153,7 +153,7 @@ typedef enum {
#define MOD_REQ_RESP_DEFAULT (PAGE_SIZE) #define MOD_REQ_RESP_DEFAULT (PAGE_SIZE)
#define QUIESCENSE_TIME (1<<20) //cycles! #define QUIESCENSE_TIME (1<<20) //cycles!
#define HTTP_HEADERS_MAX 4 #define HTTP_HEADERS_MAX 6
#define HTTP_HEADER_MAXSZ 32 #define HTTP_HEADER_MAXSZ 32
#define HTTP_HEADERVAL_MAXSZ 64 #define HTTP_HEADERVAL_MAXSZ 64

@ -63,8 +63,20 @@ u32
wasm_read(i32 filedes, i32 buf_offset, i32 nbyte) wasm_read(i32 filedes, i32 buf_offset, i32 nbyte)
{ {
if (filedes == 0) { if (filedes == 0) {
#ifdef STANDALONE
char* buf = get_memory_ptr_void(buf_offset, nbyte); char* buf = get_memory_ptr_void(buf_offset, nbyte);
return read(filedes, buf, 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); int f = io_handle_fd(filedes);
// TODO: read on other file types // 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; struct http_request *r = &s->rqi;
if (r->bodylen <= 0) return 0; if (r->bodylen <= 0) return 0;
for (int i = 0; i < iovcnt; i++) { 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; if (l <= 0) break;
char *b = get_memory_ptr_void(iov[i].base_offset, iov[i].len); char *b = get_memory_ptr_void(iov[i].base_offset, iov[i].len);
//http request body! //http request body!

@ -2,7 +2,8 @@ include Makefile.inc
BENCH_DIR=../../silverfish/code_benches/ BENCH_DIR=../../silverfish/code_benches/
TESTS=forever filesys sockserver sockclient empty TESTS=empty
#TESTS=forever filesys sockserver sockclient empty
TESTSRT=$(TESTS:%=%_rt) TESTSRT=$(TESTS:%=%_rt)
BENCHES=adpcm basic_math binarytrees bitcount blowfish crc dijkstra fft function_pointers \ BENCHES=adpcm basic_math binarytrees bitcount blowfish crc dijkstra fft function_pointers \
gsm libjpeg mandelbrot patricia pgp qsort rsynth sha sqlite stringsearch susan gsm libjpeg mandelbrot patricia pgp qsort rsynth sha sqlite stringsearch susan

@ -6,5 +6,8 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
printf("hello\n"); printf("hello\n");
// char d[16] = { 0 };
// int r = read(0, d, 15);
// printf("hello [%s]\n", d);
return 0; return 0;
} }

Loading…
Cancel
Save