diff --git a/vlib/picoev/constants_default.c.v b/vlib/picoev/constants_default.c.v new file mode 100644 index 00000000000000..fd6a083856a648 --- /dev/null +++ b/vlib/picoev/constants_default.c.v @@ -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 diff --git a/vlib/picoev/constants_windows.c.v b/vlib/picoev/constants_windows.c.v new file mode 100644 index 00000000000000..7bb24a6d419ed9 --- /dev/null +++ b/vlib/picoev/constants_windows.c.v @@ -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 diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index 0dab5bb86255a3..e75893a27faa3e 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -4,9 +4,6 @@ import net import picohttpparser import time -// maximum number of file descriptors that can be managed -pub const max_fds = 1024 - // maximum size of the event queue pub const max_queue = 4096 @@ -70,12 +67,12 @@ pub struct Picoev { max_write int = 8192 mut: 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 num_loops int buf &u8 = unsafe { nil } - idx [1024]int + idx [max_fds]int out &u8 = unsafe { nil } date string @@ -192,6 +189,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) { } if accepted_fd >= max_fds { // should never happen + elog('Error during accept, accepted_fd >= max_fd') close_socket(accepted_fd) return }