read() chunks fix, other standalone compilation fixes

main
phani 5 years ago
parent 837fc3a7c0
commit affe5fbc35

@ -20,7 +20,7 @@ struct http_request {
struct http_header headers[HTTP_HEADERS_MAX];
int nheaders;
char *body;
int bodylen;
int bodylen, bodyrlen;
// additional for http-parser
int last_was_value;
int header_end;

@ -56,7 +56,7 @@ typedef uint64_t u64;
#define WASM_START_PAGES (1<<8) //16MB
#define WASM_MAX_PAGES (1<<15) //4GB
#define WASM_STACK_SIZE (1<<14) // 16KB.
#define WASM_STACK_SIZE (1<<19) // 512KB.
#define SBOX_MAX_MEM (1L<<32) // 4GB
// These are per module symbols and I'd need to dlsym for each module. instead just use global constants, see above macros.
@ -153,7 +153,7 @@ typedef enum {
#define MOD_REQ_RESP_DEFAULT (PAGE_SIZE)
#define QUIESCENSE_TIME (1<<20) //cycles!
#define HTTP_HEADERS_MAX 6
#define HTTP_HEADERS_MAX 16
#define HTTP_HEADER_MAXSZ 32
#define HTTP_HEADERVAL_MAXSZ 64

@ -57,6 +57,7 @@ http_on_url(http_parser* parser, const char *at, size_t length)
static inline int
http_on_header_field(http_parser* parser, const char *at, size_t length)
{
#ifndef STANDALONE
struct sandbox *s = parser->data;
struct http_request *r = &s->rqi;
@ -66,6 +67,7 @@ http_on_header_field(http_parser* parser, const char *at, size_t length)
r->last_was_value = 0;
r->headers[r->nheaders - 1].key = (char *)at; //it is from the sandbox's req_resp_data, should persist.
#endif
return 0;
}
@ -73,6 +75,7 @@ http_on_header_field(http_parser* parser, const char *at, size_t length)
static inline int
http_on_header_value(http_parser* parser, const char *at, size_t length)
{
#ifndef STANDALONE
struct sandbox *s = parser->data;
struct http_request *r = &s->rqi;
@ -81,6 +84,7 @@ http_on_header_value(http_parser* parser, const char *at, size_t length)
assert(length < HTTP_HEADERVAL_MAXSZ);
r->headers[r->nheaders - 1].val = (char *)at; //it is from the sandbox's req_resp_data, should persist.
#endif
return 0;
}

@ -67,13 +67,13 @@ wasm_read(i32 filedes, i32 buf_offset, i32 nbyte)
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);
memcpy(buf, r->body + r->bodyrlen, l);
r->bodyrlen += l;
r->bodylen -= l;
return l;
#endif
@ -488,10 +488,11 @@ wasm_readv(i32 fd, i32 iov_offset, i32 iovcnt)
if (l <= 0) break;
char *b = get_memory_ptr_void(iov[i].base_offset, iov[i].len);
//http request body!
memcpy(b, r->body + len, l);
memcpy(b, r->body + r->bodyrlen + len, l);
len += l;
r->bodylen -= l;
}
r->bodyrlen += len;
return len;
#endif

@ -71,6 +71,7 @@ sandbox_args_setup(i32 argc)
static inline void
sb_read_callback(uv_stream_t *s, ssize_t nr, const uv_buf_t *b)
{
#ifndef STANDALONE
struct sandbox *c = s->data;
if (nr > 0) {
@ -82,6 +83,7 @@ sb_read_callback(uv_stream_t *s, ssize_t nr, const uv_buf_t *b)
uv_read_stop(s);
sandbox_wakeup(c);
#endif
}
static inline void
@ -101,6 +103,7 @@ sb_shutdown_callback(uv_shutdown_t *req, int status)
static inline void
sb_write_callback(uv_write_t *w, int status)
{
#ifndef STANDALONE
struct sandbox *c = w->data;
if (status < 0) {
c->cuvsr.data = c;
@ -108,6 +111,7 @@ sb_write_callback(uv_write_t *w, int status)
return;
}
sandbox_wakeup(c);
#endif
}
static inline void

@ -0,0 +1,44 @@
#ifndef GET_TIME_H
#define GET_TIME_H
#include <time.h>
#include <sys/time.h>
#ifndef WASM
#ifndef CPU_FREQ
#define CPU_FREQ 1000
#endif
#endif
static unsigned long long
get_time()
{
#if 0
unsigned long long int ret = 0;
unsigned int cycles_lo;
unsigned int cycles_hi;
__asm__ volatile ("RDTSC" : "=a" (cycles_lo), "=d" (cycles_hi));
ret = (unsigned long long int)cycles_hi << 32 | cycles_lo;
return ret;
#else
struct timeval Tp;
int stat;
stat = gettimeofday (&Tp, NULL);
if (stat != 0)
printf ("Error return from gettimeofday: %d", stat);
return (Tp.tv_sec * 1000000 + Tp.tv_usec);
#endif
}
static inline void
print_time(unsigned long long s, unsigned long long e)
{
#if 0
printf("%llu cycs, %llu us\n", e - s, (e - s) / CPU_FREQ);
#else
fprintf(stderr, "%llu us\n", e - s);
#endif
}
#endif /* GET_TIME_H */

@ -0,0 +1,23 @@
#include <stdio.h>
#include "get_time.h"
unsigned long int
fib(unsigned long int n)
{
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int
main(int argc, char **argv)
{
unsigned long n = 0, r;
scanf("%lu", &n);
unsigned long long st = get_time(), en;
r = fib(n);
en = get_time();
printf("%lu\n", r);
print_time(st, en);
return 0;
}

@ -0,0 +1,13 @@
{
"active" : "yes",
"name" : "gocr",
"path" : "gocr_wasm.so",
"port" : 10000,
"argsize" : 1,
"http-req-headers" : [ ],
"http-req-content-type" : "image/png",
"http-req-size": 10240,
"http-resp-headers" : [ ],
"http-resp-size" : 128,
"http-resp-content-type" : "text/plain"
}

@ -0,0 +1,13 @@
{
"active" : "yes",
"name" : "lpd",
"path" : "lpd_wasm.so",
"port" : 10000,
"argsize" : 1,
"http-req-headers" : [ ],
"http-req-content-type" : "image/jpeg",
"http-req-size": 102400,
"http-resp-headers" : [ ],
"http-resp-size" : 1048576,
"http-resp-content-type" : "image/jpeg"
}

@ -0,0 +1,13 @@
{
"active" : "yes",
"name" : "resize",
"path" : "resize_wasm.so",
"port" : 10000,
"argsize" : 1,
"http-req-headers" : [ ],
"http-req-content-type" : "image/jpeg",
"http-req-size": 102400,
"http-resp-headers" : [ ],
"http-resp-size" : 102400,
"http-resp-content-type" : "image/png"
}
Loading…
Cancel
Save