From 0a6d709ce292b23b4809fef5eccbe2ac9e9fcb67 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 20 May 2020 05:36:46 +0200 Subject: [PATCH] http: fix recent changes; picoev: make compile --- examples/pico/pico.v | 3 ++- vlib/net/http/backend_nix.c.v | 4 ++-- vlib/picoev/picoev.v | 33 +++++++++++++++------------- vlib/picohttpparser/picohttpparser.v | 1 - vlib/picohttpparser/request.v | 9 +++++--- vlib/picohttpparser/response.v | 2 +- vlib/v/gen/json.v | 2 +- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/examples/pico/pico.v b/examples/pico/pico.v index 85ba47efef..663a5426aa 100644 --- a/examples/pico/pico.v +++ b/examples/pico/pico.v @@ -19,7 +19,8 @@ fn hello_response() string { return 'Hello, World!' } -pub fn callback(req picohttpparser.Request, res mut picohttpparser.Response) { + +fn callback(req picohttpparser.Request, res mut picohttpparser.Response) { if picohttpparser.cmpn(req.method, 'GET ', 4) { if picohttpparser.cmp(req.path, '/t') { res.http_ok().header_server().header_date().plain().body(hello_response()) diff --git a/vlib/net/http/backend_nix.c.v b/vlib/net/http/backend_nix.c.v index 19f235cea8..cb826ad4c8 100644 --- a/vlib/net/http/backend_nix.c.v +++ b/vlib/net/http/backend_nix.c.v @@ -147,7 +147,7 @@ fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response { //println(h) sb.write(chunk.after('\r\n')) // TODO for some reason this can be missing from headers - is_chunk_encoding = true //h.contains('chunked') + is_chunk_encoding = false //h.contains('chunked') //println(sb.str()) continue } @@ -172,7 +172,7 @@ fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response { C.SSL_CTX_free(ctx) } body:= sb.str() - println(body) + //println(body) return parse_response(h +'\r\n\r\n'+ body) } diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index 7099a4e585..230003e0a1 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -63,7 +63,7 @@ fn C.write() int struct C.picoev_loop {} struct Picoev { - loop *C.picoev_loop + loop &C.picoev_loop cb fn(req picohttpparser.Request, res mut picohttpparser.Response) mut: date byteptr @@ -73,14 +73,17 @@ mut: oidx [1024]int } -fn picoev_del(*C.picoev_loop, int) int -fn picoev_set_timeout(*C.picoev_loop, int, int) -fn picoev_add(*C.picoev_loop, int, int, int, *C.picoev_handler, voidptr) int -fn picoev_init(int) int -fn picoev_create_loop(int) *C.picoev_loop -fn picoev_loop_once(*C.picoev_loop, int) int -fn picoev_destroy_loop(*C.picoev_loop) int -fn picoev_deinit() int +fn C.picoev_del(&C.picoev_loop, int) int +fn C.picoev_set_timeout(&C.picoev_loop, int, int) +fn C.picoev_add(&C.picoev_loop, int, int, int, &C.picoev_handler, voidptr) int +fn C.picoev_init(int) int +fn C.picoev_create_loop(int) &C.picoev_loop +fn C.picoev_loop_once(&C.picoev_loop, int) int +fn C.picoev_destroy_loop(&C.picoev_loop) int +fn C.picoev_deinit() int +fn C.phr_parse_request() int +fn C.phr_parse_request_path_pipeline() int +fn C.phr_parse_request_path() int [inline] fn setup_sock(fd int) { @@ -94,7 +97,7 @@ fn setup_sock(fd int) { } [inline] -fn close_conn(loop *C.picoev_loop, fd int) { +fn close_conn(loop &C.picoev_loop, fd int) { C.picoev_del(loop, fd) C.close(fd) } @@ -109,8 +112,8 @@ fn mysubstr(s byteptr, from, len int) string { return tos(s + from, len) } -fn rw_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) { - mut p := *Picoev(cb_arg) +fn rw_callback(loop &C.picoev_loop, fd, events int, cb_arg voidptr) { + mut p := &Picoev(cb_arg) if (events & C.PICOEV_TIMEOUT) != 0 { close_conn(loop, fd) p.idx[fd] = 0 @@ -126,8 +129,8 @@ fn rw_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) { p.idx[fd] = 0 return } else if r == -1 { - if errno == C.EAGAIN || errno == C.EWOULDBLOCK { - // + if false { //errno == C.EAGAIN || errno == C.EWOULDBLOCK { + // TODO } else { close_conn(loop, fd) p.idx[fd] = 0 @@ -168,7 +171,7 @@ fn rw_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) { } } -fn accept_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) { +fn accept_callback(loop &C.picoev_loop, fd, events int, cb_arg voidptr) { newfd := C.accept(fd, 0, 0) if newfd != -1 { setup_sock(newfd) diff --git a/vlib/picohttpparser/picohttpparser.v b/vlib/picohttpparser/picohttpparser.v index 99af275352..9a77a87e14 100644 --- a/vlib/picohttpparser/picohttpparser.v +++ b/vlib/picohttpparser/picohttpparser.v @@ -26,4 +26,3 @@ fn phr_parse_request_path() int fn phr_parse_request_path_pipeline() int fn C.get_date() byteptr fn C.u64toa() int -fn C.memcmp() int diff --git a/vlib/picohttpparser/request.v b/vlib/picohttpparser/request.v index eec3c33a00..8aff6c3bfe 100644 --- a/vlib/picohttpparser/request.v +++ b/vlib/picohttpparser/request.v @@ -1,15 +1,18 @@ module picohttpparser pub struct Request { -mut: +pub mut: method string path string - headers *C.phr_header_t + headers &C.phr_header_t num_headers u64 } + + + [inline] -pub fn (mut r Request) parse_request(s string, headers *C.phr_header_t, max_headers int) int { +pub fn (mut r Request) parse_request(s string, headers &C.phr_header_t, max_headers int) int { method_len := u64(0) path_len := u64(0) minor_version := 0 diff --git a/vlib/picohttpparser/response.v b/vlib/picohttpparser/response.v index a7b914124e..dcc44a830a 100644 --- a/vlib/picohttpparser/response.v +++ b/vlib/picohttpparser/response.v @@ -5,7 +5,7 @@ pub struct Response { pub: date byteptr buf_start byteptr -mut: +pub mut: buf byteptr } diff --git a/vlib/v/gen/json.v b/vlib/v/gen/json.v index 18c1b69139..3a3d4bd969 100644 --- a/vlib/v/gen/json.v +++ b/vlib/v/gen/json.v @@ -44,7 +44,7 @@ Option ${dec_fn_name}(cJSON* root) { if (!root) { const char *error_ptr = cJSON_GetErrorPtr(); if (error_ptr != NULL) { - fprintf(stderr, "Error in decode() for $styp error_ptr=: %%s\\n", error_ptr); +// fprintf(stderr, "Error in decode() for $styp error_ptr=: %%s\\n", error_ptr); // printf("\\nbad js=%%s\\n", js.str); return v_error(tos2(error_ptr)); }