From d1f044d089cfc2728c967162cff8fa5eeec1b8f1 Mon Sep 17 00:00:00 2001 From: l-m Date: Sun, 5 Nov 2023 08:49:54 +0000 Subject: [PATCH] picoev: implement raw mode (#19771) --- vlib/picoev/picoev.v | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index f8e1d92a2f36d0..4c111126eee64d 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -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 @@ -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 @@ -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 { @@ -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