mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
picoev: implement raw mode (#19771)
This commit is contained in:
parent
0f424b8d54
commit
d1f044d089
1 changed files with 12 additions and 2 deletions
|
@ -33,6 +33,7 @@ pub:
|
||||||
port int = 8080
|
port int = 8080
|
||||||
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) = unsafe { nil }
|
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) = unsafe { nil }
|
||||||
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) = default_err_cb
|
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) = default_err_cb
|
||||||
|
raw_cb fn (voidptr, int) = unsafe { nil }
|
||||||
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
|
||||||
|
@ -44,6 +45,7 @@ pub:
|
||||||
pub struct Picoev {
|
pub struct Picoev {
|
||||||
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) = unsafe { nil }
|
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) = unsafe { nil }
|
||||||
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) = default_err_cb
|
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) = default_err_cb
|
||||||
|
raw_cb fn (voidptr, int) = unsafe { nil }
|
||||||
user_data voidptr = unsafe { nil }
|
user_data voidptr = unsafe { nil }
|
||||||
|
|
||||||
timeout_secs int
|
timeout_secs int
|
||||||
|
@ -210,6 +212,10 @@ fn raw_callback(fd int, events int, context voidptr) {
|
||||||
return
|
return
|
||||||
} else if events & picoev.picoev_read != 0 {
|
} else if events & picoev.picoev_read != 0 {
|
||||||
pv.set_timeout(fd, pv.timeout_secs)
|
pv.set_timeout(fd, pv.timeout_secs)
|
||||||
|
if !isnil(pv.raw_cb) {
|
||||||
|
pv.raw_cb(pv.user_data, fd)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
mut buf := pv.buf
|
mut buf := pv.buf
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -283,13 +289,17 @@ pub fn new(config Config) &Picoev {
|
||||||
num_loops: 1
|
num_loops: 1
|
||||||
cb: config.cb
|
cb: config.cb
|
||||||
err_cb: config.err_cb
|
err_cb: config.err_cb
|
||||||
|
raw_cb: config.raw_cb
|
||||||
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_read: config.max_read
|
||||||
max_write: config.max_write
|
max_write: config.max_write
|
||||||
buf: unsafe { malloc_noscan(picoev.max_fds * config.max_read + 1) }
|
}
|
||||||
out: unsafe { malloc_noscan(picoev.max_fds * config.max_write + 1) }
|
|
||||||
|
if isnil(pv.raw_cb) {
|
||||||
|
pv.buf = unsafe { malloc_noscan(picoev.max_fds * config.max_read + 1) }
|
||||||
|
pv.out = unsafe { malloc_noscan(picoev.max_fds * config.max_write + 1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// epoll for linux
|
// epoll for linux
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue