mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
picoev: non breaking refactor (#18364)
This commit is contained in:
parent
691bc0e7b2
commit
6208b31d9f
@ -39,8 +39,6 @@ fn C.picoev_deinit() int
|
|||||||
const (
|
const (
|
||||||
max_fds = 1024
|
max_fds = 1024
|
||||||
max_timeout = 10
|
max_timeout = 10
|
||||||
max_read = 4096
|
|
||||||
max_write = 8192
|
|
||||||
)
|
)
|
||||||
|
|
||||||
enum Event {
|
enum Event {
|
||||||
@ -60,6 +58,8 @@ pub:
|
|||||||
user_data voidptr = unsafe { nil }
|
user_data voidptr = unsafe { nil }
|
||||||
timeout_secs int = 8
|
timeout_secs int = 8
|
||||||
max_headers int = 100
|
max_headers int = 100
|
||||||
|
max_read int = 4096
|
||||||
|
max_write int = 8192
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Picoev {
|
struct Picoev {
|
||||||
@ -69,6 +69,8 @@ struct Picoev {
|
|||||||
user_data voidptr
|
user_data voidptr
|
||||||
timeout_secs int
|
timeout_secs int
|
||||||
max_headers int
|
max_headers int
|
||||||
|
max_read int
|
||||||
|
max_write int
|
||||||
mut:
|
mut:
|
||||||
date &u8 = unsafe { nil }
|
date &u8 = unsafe { nil }
|
||||||
buf &u8 = unsafe { nil }
|
buf &u8 = unsafe { nil }
|
||||||
@ -114,14 +116,14 @@ fn rw_callback(loop &C.picoev_loop, fd int, events int, context voidptr) {
|
|||||||
// Request init
|
// Request init
|
||||||
mut buf := p.buf
|
mut buf := p.buf
|
||||||
unsafe {
|
unsafe {
|
||||||
buf += fd * picoev.max_read // pointer magic
|
buf += fd * p.max_read // pointer magic
|
||||||
}
|
}
|
||||||
mut req := picohttpparser.Request{}
|
mut req := picohttpparser.Request{}
|
||||||
|
|
||||||
// Response init
|
// Response init
|
||||||
mut out := p.out
|
mut out := p.out
|
||||||
unsafe {
|
unsafe {
|
||||||
out += fd * picoev.max_write // pointer magic
|
out += fd * p.max_write // pointer magic
|
||||||
}
|
}
|
||||||
mut res := picohttpparser.Response{
|
mut res := picohttpparser.Response{
|
||||||
fd: fd
|
fd: fd
|
||||||
@ -132,7 +134,7 @@ fn rw_callback(loop &C.picoev_loop, fd int, events int, context voidptr) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
// Request parsing loop
|
// Request parsing loop
|
||||||
r := req_read(fd, buf, picoev.max_read, p.idx[fd]) // Get data from socket
|
r := req_read(fd, buf, p.max_read, p.idx[fd]) // Get data from socket
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
// connection closed by peer
|
// connection closed by peer
|
||||||
close_conn(loop, fd)
|
close_conn(loop, fd)
|
||||||
@ -234,9 +236,11 @@ pub fn new(config Config) &Picoev {
|
|||||||
user_data: config.user_data
|
user_data: config.user_data
|
||||||
timeout_secs: config.timeout_secs
|
timeout_secs: config.timeout_secs
|
||||||
max_headers: config.max_headers
|
max_headers: config.max_headers
|
||||||
|
max_read: config.max_read
|
||||||
|
max_write: config.max_write
|
||||||
date: &u8(C.get_date())
|
date: &u8(C.get_date())
|
||||||
buf: unsafe { malloc_noscan(picoev.max_fds * picoev.max_read + 1) }
|
buf: unsafe { malloc_noscan(picoev.max_fds * config.max_read + 1) }
|
||||||
out: unsafe { malloc_noscan(picoev.max_fds * picoev.max_write + 1) }
|
out: unsafe { malloc_noscan(picoev.max_fds * config.max_write + 1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
C.picoev_add(voidptr(loop), fd, int(Event.read), 0, accept_callback, pv)
|
C.picoev_add(voidptr(loop), fd, int(Event.read), 0, accept_callback, pv)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module picohttpparser
|
module picohttpparser
|
||||||
|
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
fd int
|
|
||||||
pub:
|
pub:
|
||||||
|
fd int
|
||||||
date &u8 = unsafe { nil }
|
date &u8 = unsafe { nil }
|
||||||
buf_start &u8 = unsafe { nil }
|
buf_start &u8 = unsafe { nil }
|
||||||
pub mut:
|
pub mut:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user