Skip to content

Commit d5aa37d

Browse files
authored
picoev: fix for windows apps with veb in a thread, parallel to a webview, that opens a lot of file descriptors (#23492)
1 parent d23e70f commit d5aa37d

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

vlib/picoev/constants_default.c.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module picoev
2+
3+
// max_fds is the maximum number of file descriptors that can be managed.
4+
// Many sizes depend on it, and some internal arrays are also iterated based on it,
5+
// so increasing it a lot can slow down looping :-| .
6+
pub const max_fds = 1024

vlib/picoev/constants_windows.c.v

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

vlib/picoev/picoev.v

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import net
44
import picohttpparser
55
import time
66

7-
// maximum number of file descriptors that can be managed
8-
pub const max_fds = 1024
9-
107
// maximum size of the event queue
118
pub const max_queue = 4096
129

@@ -70,12 +67,12 @@ pub struct Picoev {
7067
max_write int = 8192
7168
mut:
7269
loop &LoopType = unsafe { nil }
73-
file_descriptors [max_fds]&Target
70+
file_descriptors [4096]&Target // TODO: use max_fds here, instead of the hardcoded size, when the compiler allows it
7471
timeouts map[int]i64
7572
num_loops int
7673

7774
buf &u8 = unsafe { nil }
78-
idx [1024]int
75+
idx [max_fds]int
7976
out &u8 = unsafe { nil }
8077

8178
date string
@@ -192,6 +189,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
192189
}
193190
if accepted_fd >= max_fds {
194191
// should never happen
192+
elog('Error during accept, accepted_fd >= max_fd')
195193
close_socket(accepted_fd)
196194
return
197195
}

0 commit comments

Comments
 (0)