Skip to content

Commit

Permalink
picoev: implement raw mode (#19771)
Browse files Browse the repository at this point in the history
  • Loading branch information
l1mey112 committed Nov 5, 2023
1 parent 0f424b8 commit d1f044d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions vlib/picoev/picoev.v
Expand Up @@ -33,6 +33,7 @@ pub:
port int = 8080
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) = unsafe { nil }
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 }
timeout_secs int = 8
max_headers int = 100
Expand All @@ -44,6 +45,7 @@ pub:
pub struct Picoev {
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) = unsafe { nil }
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 }

timeout_secs int
Expand Down Expand Up @@ -210,6 +212,10 @@ fn raw_callback(fd int, events int, context voidptr) {
return
} else if events & picoev.picoev_read != 0 {
pv.set_timeout(fd, pv.timeout_secs)
if !isnil(pv.raw_cb) {
pv.raw_cb(pv.user_data, fd)
return
}

mut buf := pv.buf
unsafe {
Expand Down Expand Up @@ -283,13 +289,17 @@ pub fn new(config Config) &Picoev {
num_loops: 1
cb: config.cb
err_cb: config.err_cb
raw_cb: config.raw_cb
user_data: config.user_data
timeout_secs: config.timeout_secs
max_headers: config.max_headers
max_read: config.max_read
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
Expand Down

0 comments on commit d1f044d

Please sign in to comment.