ci: fix `v -cc gcc -cstrict examples/pico/pico.v`

pull/12037/head
Delyan Angelov 2021-10-01 13:49:38 +03:00
parent 6f7c3a7cdf
commit 41de0c3c6a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
5 changed files with 28 additions and 22 deletions

View File

@ -6,7 +6,7 @@ typedef struct phr_header phr_header_t;
#define ADVANCE_TOKEN2(buf, tok, toklen, max_len) \
do {\
for (int i = 0; i < max_len; i++) {\
for (u32 i = 0; i < max_len; i++) {\
if (buf[i] == ' ') {\
tok = buf;\
toklen = i++;\

View File

@ -16,7 +16,7 @@ import picohttpparser
struct C.in_addr {
mut:
s_addr int
s_addr u32
}
struct C.sockaddr_in {
@ -32,6 +32,7 @@ fn C.atoi() int
fn C.strncasecmp(s1 &char, s2 &char, n usize) int
[typedef]
struct C.picoev_loop {}
fn C.picoev_del(&C.picoev_loop, int) int
@ -107,7 +108,7 @@ fn setup_sock(fd int) ? {
[inline]
fn close_conn(loop &C.picoev_loop, fd int) {
C.picoev_del(loop, fd)
C.picoev_del(voidptr(loop), fd)
C.close(fd)
}
@ -127,7 +128,7 @@ fn rw_callback(loop &C.picoev_loop, fd int, events int, context voidptr) {
close_conn(loop, fd)
return
} else if (events & int(Event.read)) != 0 {
C.picoev_set_timeout(loop, fd, p.timeout_secs)
C.picoev_set_timeout(voidptr(loop), fd, p.timeout_secs)
// Request init
mut buf := p.buf
@ -157,14 +158,17 @@ fn rw_callback(loop &C.picoev_loop, fd int, events int, context voidptr) {
return
} else if r == -1 {
// error
if C.errno == C.EAGAIN || C.errno == C.EWOULDBLOCK {
if C.errno == C.EAGAIN {
// try again later
return
} else {
// fatal error
close_conn(loop, fd)
}
if C.errno == C.EWOULDBLOCK {
// try again later
return
}
// fatal error
close_conn(loop, fd)
return
}
p.idx[fd] += r
@ -198,7 +202,8 @@ fn accept_callback(loop &C.picoev_loop, fd int, events int, cb_arg voidptr) {
p.err_cb(mut p.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
err)
}
C.picoev_add(loop, newfd, int(Event.read), p.timeout_secs, rw_callback, cb_arg)
C.picoev_add(voidptr(loop), newfd, int(Event.read), p.timeout_secs, rw_callback,
cb_arg)
}
}
@ -225,7 +230,7 @@ pub fn new(config Config) &Picoev {
addr.sin_port = C.htons(config.port)
addr.sin_addr.s_addr = C.htonl(C.INADDR_ANY)
size := 16 // sizeof(C.sockaddr_in)
bind_res := C.bind(fd, unsafe { &net.Addr(&addr) }, size)
bind_res := C.bind(fd, voidptr(unsafe { &net.Addr(&addr) }), size)
assert bind_res == 0
listen_res := C.listen(fd, C.SOMAXCONN)
assert listen_res == 0
@ -242,11 +247,11 @@ pub fn new(config Config) &Picoev {
user_data: config.user_data
timeout_secs: config.timeout_secs
max_headers: config.max_headers
date: C.get_date()
date: &byte(C.get_date())
buf: unsafe { malloc_noscan(picoev.max_fds * picoev.max_read + 1) }
out: unsafe { malloc_noscan(picoev.max_fds * picoev.max_write + 1) }
}
C.picoev_add(loop, fd, int(Event.read), 0, accept_callback, pv)
C.picoev_add(voidptr(loop), fd, int(Event.read), 0, accept_callback, pv)
go update_date(mut pv)
return pv
}
@ -259,7 +264,7 @@ pub fn (p Picoev) serve() {
fn update_date(mut p Picoev) {
for {
p.date = C.get_date()
p.date = &byte(C.get_date())
C.usleep(1000000)
}
}

View File

@ -29,7 +29,7 @@ fn C.phr_parse_headers(buf &char, len usize, headers &C.phr_header, num_headers
fn C.phr_parse_request_path(buf_start &char, len usize, method PPchar, method_len &usize, path PPchar, path_len &usize) int
fn C.phr_parse_request_path_pipeline(buf_start &char, len usize, method PPchar, method_len &usize, path PPchar, path_len &usize) int
fn C.get_date() &byte
fn C.get_date() &char
// static inline int u64toa(char* buf, uint64_t value) {
fn C.u64toa(buffer &char, value u64) int

View File

@ -18,8 +18,9 @@ pub fn (mut r Request) parse_request(s string, max_headers int) int {
minor_version := 0
num_headers := usize(max_headers)
pret := C.phr_parse_request(s.str, s.len, PPchar(&r.method.str), &method_len, PPchar(&r.path.str),
&path_len, &minor_version, &r.headers[0], &num_headers, r.prev_len)
pret := C.phr_parse_request(&char(s.str), s.len, voidptr(&r.method.str), &method_len,
voidptr(&r.path.str), &path_len, &minor_version, &r.headers[0], &num_headers,
r.prev_len)
if pret > 0 {
unsafe {
r.method = tos(r.method.str, int(method_len))
@ -37,8 +38,8 @@ pub fn (mut r Request) parse_request_path(s string) int {
method_len := usize(0)
path_len := usize(0)
pret := C.phr_parse_request_path(s.str, s.len, PPchar(&r.method.str), &method_len,
PPchar(&r.path.str), &path_len)
pret := C.phr_parse_request_path(&char(s.str), s.len, voidptr(&r.method.str), &method_len,
voidptr(&r.path.str), &path_len)
if pret > 0 {
unsafe {
r.method = tos(r.method.str, int(method_len))
@ -53,8 +54,8 @@ pub fn (mut r Request) parse_request_path_pipeline(s string) int {
method_len := usize(0)
path_len := usize(0)
pret := C.phr_parse_request_path_pipeline(s.str, s.len, PPchar(&r.method.str), &method_len,
PPchar(&r.path.str), &path_len)
pret := C.phr_parse_request_path_pipeline(&char(s.str), s.len, voidptr(&r.method.str),
&method_len, voidptr(&r.path.str), &path_len)
if pret > 0 {
unsafe {
r.method = tos(r.method.str, int(method_len))

View File

@ -78,7 +78,7 @@ pub fn (mut r Response) json() &Response {
pub fn (mut r Response) body(body string) {
r.write_string('Content-Length: ')
unsafe {
r.buf += C.u64toa(r.buf, body.len)
r.buf += C.u64toa(&char(r.buf), body.len)
}
r.write_string('\r\n\r\n')
r.write_string(body)
@ -106,7 +106,7 @@ pub fn (mut r Response) raw(response string) {
[inline]
pub fn (mut r Response) end() int {
n := int(r.buf) - int(r.buf_start)
n := int(i64(r.buf) - i64(r.buf_start))
if C.write(r.fd, r.buf_start, n) != n {
return -1
}