picoev: fix for windows apps with veb in a thread, parallel to a webview, that opens a lot of file descriptors (#23492)

This commit is contained in:
Delyan Angelov 2025-01-17 01:03:49 +02:00 committed by GitHub
parent d23e70f546
commit d5aa37d8b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 5 deletions

View file

@ -0,0 +1,6 @@
module picoev
// max_fds is the maximum number of file descriptors that can be managed.
// Many sizes depend on it, and some internal arrays are also iterated based on it,
// so increasing it a lot can slow down looping :-| .
pub const max_fds = 1024

View file

@ -0,0 +1,11 @@
module picoev
// max_fds is the maximum number of file descriptors that can be managed.
// Many sizes depend on it, and some internal arrays are also iterated based on it,
// so increasing it a lot can slow down looping :-| .
// It is higher on windows, because if you start a veb/picoev webservice in a thread,
// the returned file descriptors can be higher than 1024 in value, especially if you
// also have a webview running in another thread, that also opens its own file descriptors.
// Note: this works, because on windows we use select, and select on win32,
// is not limited to polling on only 1024 fds.
pub const max_fds = 4096

View file

@ -4,9 +4,6 @@ import net
import picohttpparser import picohttpparser
import time import time
// maximum number of file descriptors that can be managed
pub const max_fds = 1024
// maximum size of the event queue // maximum size of the event queue
pub const max_queue = 4096 pub const max_queue = 4096
@ -70,12 +67,12 @@ pub struct Picoev {
max_write int = 8192 max_write int = 8192
mut: mut:
loop &LoopType = unsafe { nil } loop &LoopType = unsafe { nil }
file_descriptors [max_fds]&Target file_descriptors [4096]&Target // TODO: use max_fds here, instead of the hardcoded size, when the compiler allows it
timeouts map[int]i64 timeouts map[int]i64
num_loops int num_loops int
buf &u8 = unsafe { nil } buf &u8 = unsafe { nil }
idx [1024]int idx [max_fds]int
out &u8 = unsafe { nil } out &u8 = unsafe { nil }
date string date string
@ -192,6 +189,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
} }
if accepted_fd >= max_fds { if accepted_fd >= max_fds {
// should never happen // should never happen
elog('Error during accept, accepted_fd >= max_fd')
close_socket(accepted_fd) close_socket(accepted_fd)
return return
} }