Skip to content

Commit 6cbffd5

Browse files
authored
picoev: fix documentation (#24811)
1 parent b909e2e commit 6cbffd5

File tree

8 files changed

+50
-44
lines changed

8 files changed

+50
-44
lines changed

vlib/picoev/loop_default.c.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ mut:
1515

1616
type LoopType = SelectLoop
1717

18-
// create_select_loop creates a new `SelectLoop` struct with the given `id`
18+
// create_select_loop creates a new `SelectLoop` struct with the given `id`.
1919
pub fn create_select_loop(id int) !&SelectLoop {
2020
return &SelectLoop{
2121
id: id
2222
}
2323
}
2424

25-
// updates the events associated with a file descriptor in the event loop
25+
// updates the events associated with a file descriptor in the event loop.
2626
@[direct_array_access]
2727
fn (mut pv Picoev) update_events(fd int, events int) int {
2828
// check if fd is in range
@@ -32,7 +32,7 @@ fn (mut pv Picoev) update_events(fd int, events int) int {
3232
return 0
3333
}
3434

35-
// performs a single iteration of the select-based event loop
35+
// performs a single iteration of the select-based event loop.
3636
@[direct_array_access]
3737
fn (mut pv Picoev) poll_once(max_wait_in_sec int) int {
3838
// Initializes sets for read, write, and error events

vlib/picoev/loop_freebsd.c.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mut:
3434

3535
type LoopType = KqueueLoop
3636

37-
// create_kqueue_loop creates a new kernel event queue with loop_id=`id`
37+
// create_kqueue_loop creates a new kernel event queue with loop_id=`id`.
3838
pub fn create_kqueue_loop(id int) !&KqueueLoop {
3939
mut loop := &KqueueLoop{
4040
id: id
@@ -48,7 +48,7 @@ pub fn create_kqueue_loop(id int) !&KqueueLoop {
4848
return loop
4949
}
5050

51-
// ev_set sets a new `kevent` with file descriptor `index`
51+
// ev_set sets a new `kevent` with file descriptor `index`.
5252
@[inline]
5353
pub fn (mut pv Picoev) ev_set(index int, operation int, events int) {
5454
mut filter := 0
@@ -65,26 +65,26 @@ pub fn (mut pv Picoev) ev_set(index int, operation int, events int) {
6565
}
6666

6767
// backend_build uses the lower 8 bits to store the old events and the higher 8
68-
// bits to store the next file descriptor in `Target.backend`
68+
// bits to store the next file descriptor in `Target.backend`.
6969
@[inline]
7070
fn backend_build(next_fd int, events u32) int {
7171
return int((u32(next_fd) << 8) | (events & 0xff))
7272
}
7373

74-
// get the lower 8 bits
74+
// get the lower 8 bits.
7575
@[inline]
7676
fn backend_get_old_events(backend int) int {
7777
return backend & 0xff
7878
}
7979

80-
// get the higher 8 bits
80+
// get the higher 8 bits.
8181
@[inline]
8282
fn backend_get_next_fd(backend int) int {
8383
return backend >> 8
8484
}
8585

8686
// apply pending processes all changes for the file descriptors and updates `loop.changelist`
87-
// if `aplly_all` is `true` the changes are immediately applied
87+
// if `aplly_all` is `true` the changes are immediately applied.
8888
fn (mut pv Picoev) apply_pending_changes(apply_all bool) int {
8989
mut total, mut nevents := 0, 0
9090

vlib/picoev/loop_linux.c.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ mut:
3636

3737
type LoopType = EpollLoop
3838

39-
// create_epoll_loop creates a new epoll instance for and returns an
40-
// `EpollLoop` struct with `id`
39+
// create_epoll_loop creates a new epoll instance and returns an
40+
// `EpollLoop` struct with `id`.
4141
pub fn create_epoll_loop(id int) !&EpollLoop {
4242
mut loop := &EpollLoop{
4343
id: id
@@ -51,6 +51,7 @@ pub fn create_epoll_loop(id int) !&EpollLoop {
5151
return loop
5252
}
5353

54+
// updates the events associated with a file descriptor in the event loop.
5455
@[direct_array_access]
5556
fn (mut pv Picoev) update_events(fd int, events int) int {
5657
// check if fd is in range
@@ -103,6 +104,7 @@ fn (mut pv Picoev) update_events(fd int, events int) int {
103104
return 0
104105
}
105106

107+
// performs a single iteration of the select-based event loop.
106108
@[direct_array_access]
107109
fn (mut pv Picoev) poll_once(max_wait_in_sec int) int {
108110
nevents := C.epoll_wait(pv.loop.epoll_fd, &pv.loop.events[0], max_fds, max_wait_in_sec * 1000)

vlib/picoev/loop_macos.c.v

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mut:
3434

3535
type LoopType = KqueueLoop
3636

37-
// create_kqueue_loop creates a new kernel event queue with loop_id=`id`
37+
// create_kqueue_loop creates a new kernel event queue with loop_id=`id`.
3838
pub fn create_kqueue_loop(id int) !&KqueueLoop {
3939
mut loop := &KqueueLoop{
4040
id: id
@@ -48,7 +48,7 @@ pub fn create_kqueue_loop(id int) !&KqueueLoop {
4848
return loop
4949
}
5050

51-
// ev_set sets a new `kevent` with file descriptor `index`
51+
// ev_set sets a new `kevent` with file descriptor `index`.
5252
@[inline]
5353
pub fn (mut pv Picoev) ev_set(index int, operation int, events int) {
5454
mut filter := 0
@@ -65,26 +65,26 @@ pub fn (mut pv Picoev) ev_set(index int, operation int, events int) {
6565
}
6666

6767
// backend_build uses the lower 8 bits to store the old events and the higher 8
68-
// bits to store the next file descriptor in `Target.backend`
68+
// bits to store the next file descriptor in `Target.backend`.
6969
@[inline]
7070
fn backend_build(next_fd int, events u32) int {
7171
return int((u32(next_fd) << 8) | (events & 0xff))
7272
}
7373

74-
// get the lower 8 bits
74+
// get the lower 8 bits.
7575
@[inline]
7676
fn backend_get_old_events(backend int) int {
7777
return backend & 0xff
7878
}
7979

80-
// get the higher 8 bits
80+
// get the higher 8 bits.
8181
@[inline]
8282
fn backend_get_next_fd(backend int) int {
8383
return backend >> 8
8484
}
8585

8686
// apply pending processes all changes for the file descriptors and updates `loop.changelist`
87-
// if `aplly_all` is `true` the changes are immediately applied
87+
// if `aplly_all` is `true` the changes are immediately applied.
8888
fn (mut pv Picoev) apply_pending_changes(apply_all bool) int {
8989
mut total, mut nevents := 0, 0
9090

@@ -123,6 +123,7 @@ fn (mut pv Picoev) apply_pending_changes(apply_all bool) int {
123123
return total
124124
}
125125

126+
// updates the events associated with a file descriptor in the event loop.
126127
@[direct_array_access]
127128
fn (mut pv Picoev) update_events(fd int, events int) int {
128129
// check if fd is in range
@@ -157,6 +158,7 @@ fn (mut pv Picoev) update_events(fd int, events int) int {
157158
return 0
158159
}
159160

161+
// performs a single iteration of the select-based event loop.
160162
@[direct_array_access]
161163
fn (mut pv Picoev) poll_once(max_wait_in_sec int) int {
162164
ts := C.timespec{

vlib/picoev/loop_openbsd.c.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mut:
3434

3535
type LoopType = KqueueLoop
3636

37-
// create_kqueue_loop creates a new kernel event queue with loop_id=`id`
37+
// create_kqueue_loop creates a new kernel event queue with loop_id=`id`.
3838
pub fn create_kqueue_loop(id int) !&KqueueLoop {
3939
mut loop := &KqueueLoop{
4040
id: id
@@ -48,7 +48,7 @@ pub fn create_kqueue_loop(id int) !&KqueueLoop {
4848
return loop
4949
}
5050

51-
// ev_set sets a new `kevent` with file descriptor `index`
51+
// ev_set sets a new `kevent` with file descriptor `index`.
5252
@[inline]
5353
pub fn (mut pv Picoev) ev_set(index int, operation int, events int) {
5454
mut filter := 0
@@ -65,7 +65,7 @@ pub fn (mut pv Picoev) ev_set(index int, operation int, events int) {
6565
}
6666

6767
// backend_build uses the lower 8 bits to store the old events and the higher 8
68-
// bits to store the next file descriptor in `Target.backend`
68+
// bits to store the next file descriptor in `Target.backend`.
6969
@[inline]
7070
fn backend_build(next_fd int, events u32) int {
7171
return int((u32(next_fd) << 8) | (events & 0xff))
@@ -84,7 +84,7 @@ fn backend_get_next_fd(backend int) int {
8484
}
8585

8686
// apply pending processes all changes for the file descriptors and updates `loop.changelist`
87-
// if `aplly_all` is `true` the changes are immediately applied
87+
// if `aplly_all` is `true` the changes are immediately applied.
8888
fn (mut pv Picoev) apply_pending_changes(apply_all bool) int {
8989
mut total, mut nevents := 0, 0
9090

vlib/picoev/loop_termux.c.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ mut:
3636

3737
type LoopType = EpollLoop
3838

39-
// create_epoll_loop creates a new epoll instance for and returns an
40-
// `EpollLoop` struct with `id`
39+
// create_epoll_loop creates a new epoll instance and returns an
40+
// `EpollLoop` struct with `id`.
4141
pub fn create_epoll_loop(id int) !&EpollLoop {
4242
mut loop := &EpollLoop{
4343
id: id
@@ -51,6 +51,7 @@ pub fn create_epoll_loop(id int) !&EpollLoop {
5151
return loop
5252
}
5353

54+
// updates the events associated with a file descriptor in the event loop.
5455
@[direct_array_access]
5556
fn (mut pv Picoev) update_events(fd int, events int) int {
5657
// check if fd is in range
@@ -103,6 +104,7 @@ fn (mut pv Picoev) update_events(fd int, events int) int {
103104
return 0
104105
}
105106

107+
// performs a single iteration of the select-based event loop.
106108
@[direct_array_access]
107109
fn (mut pv Picoev) poll_once(max_wait_in_sec int) int {
108110
nevents := C.epoll_wait(pv.loop.epoll_fd, &pv.loop.events[0], max_fds, max_wait_in_sec * 1000)

vlib/picoev/picoev.v

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ import net
44
import picohttpparser
55
import time
66

7-
// maximum size of the event queue
7+
// maximum size of the event queue.
88
pub const max_queue = 4096
99

10-
// event for incoming data ready to be read on a socket
10+
// event for incoming data ready to be read on a socket.
1111
pub const picoev_read = 1
1212

13-
// event for socket ready for writing
13+
// event for socket ready for writing.
1414
pub const picoev_write = 2
1515

16-
// event indicating a timeout has occurred
16+
// event indicating a timeout has occurred.
1717
pub const picoev_timeout = 4
1818

19-
// flag for adding a file descriptor to the event loop
19+
// flag for adding a file descriptor to the event loop.
2020
pub const picoev_add = 0x40000000
2121

22-
// flag for removing a file descriptor from the event loop
22+
// flag for removing a file descriptor from the event loop.
2323
pub const picoev_del = 0x20000000
2424

25-
// event read/write
25+
// event read/write.
2626
pub const picoev_readwrite = 3
2727

2828
// Target is a data representation of everything that needs to be associated with a single
29-
// file descriptor (connection)
29+
// file descriptor (connection).
3030
pub struct Target {
3131
pub mut:
3232
fd int // file descriptor
@@ -37,7 +37,7 @@ pub mut:
3737
backend int
3838
}
3939

40-
// Config configures the Picoev instance with server settings and callbacks
40+
// Config configures the Picoev instance with server settings and callbacks.
4141
pub struct Config {
4242
pub:
4343
port int = 8080
@@ -80,7 +80,7 @@ pub:
8080
user_data voidptr = unsafe { nil }
8181
}
8282

83-
// init fills the `file_descriptors` array
83+
// init fills the `file_descriptors` array.
8484
pub fn (mut pv Picoev) init() {
8585
// assert max_fds > 0
8686
pv.num_loops = 0
@@ -89,7 +89,7 @@ pub fn (mut pv Picoev) init() {
8989
}
9090
}
9191

92-
// add a file descriptor to the event loop
92+
// add a file descriptor to the event loop.
9393
@[direct_array_access]
9494
pub fn (mut pv Picoev) add(fd int, events int, timeout int, callback voidptr) int {
9595
if pv == unsafe { nil } || fd < 0 || fd >= max_fds {
@@ -110,7 +110,7 @@ pub fn (mut pv Picoev) add(fd int, events int, timeout int, callback voidptr) in
110110
return 0
111111
}
112112

113-
// remove a file descriptor from the event loop
113+
// remove a file descriptor from the event loop.
114114
@[direct_array_access]
115115
pub fn (mut pv Picoev) delete(fd int) int {
116116
if fd < 0 || fd >= max_fds {
@@ -146,7 +146,7 @@ fn (mut pv Picoev) loop_once(max_wait_in_sec int) int {
146146
}
147147

148148
// set_timeout sets the timeout in seconds for a file descriptor. If a timeout occurs
149-
// the file descriptors target callback is called with a timeout event
149+
// the file descriptors target callback is called with a timeout event.
150150
@[direct_array_access; inline]
151151
fn (mut pv Picoev) set_timeout(fd int, secs int) {
152152
assert fd < max_fds
@@ -159,7 +159,7 @@ fn (mut pv Picoev) set_timeout(fd int, secs int) {
159159

160160
// handle_timeout loops over all file descriptors and removes them from the loop
161161
// if they are timed out. Also the file descriptors target callback is called with a
162-
// timeout event
162+
// timeout event.
163163
@[direct_array_access; inline]
164164
fn (mut pv Picoev) handle_timeout() {
165165
mut to_remove := []int{}
@@ -176,7 +176,7 @@ fn (mut pv Picoev) handle_timeout() {
176176
}
177177
}
178178

179-
// accept_callback accepts a new connection from `listen_fd` and adds it to the event loop
179+
// accept_callback accepts a new connection from `listen_fd` and adds it to the event loop.
180180
fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
181181
mut pv := unsafe { &Picoev(cb_arg) }
182182
accepted_fd := accept(listen_fd)
@@ -204,7 +204,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
204204
pv.add(accepted_fd, picoev_read, pv.timeout_secs, raw_callback)
205205
}
206206

207-
// close_conn closes the socket `fd` and removes it from the loop
207+
// close_conn closes the socket `fd` and removes it from the loop.
208208
@[inline]
209209
pub fn (mut pv Picoev) close_conn(fd int) {
210210
if pv.delete(fd) != 0 {
@@ -213,7 +213,7 @@ pub fn (mut pv Picoev) close_conn(fd int) {
213213
close_socket(fd)
214214
}
215215

216-
// raw_callback handles raw events (read, write, timeout) for a file descriptor
216+
// raw_callback handles raw events (read, write, timeout) for a file descriptor.
217217
@[direct_array_access]
218218
fn raw_callback(fd int, events int, context voidptr) {
219219
mut pv := unsafe { &Picoev(context) }
@@ -299,7 +299,7 @@ fn default_error_callback(data voidptr, req picohttpparser.Request, mut res pico
299299
res.end()
300300
}
301301

302-
// new creates a `Picoev` struct and initializes the main loop
302+
// new creates a `Picoev` struct and initializes the main loop.
303303
pub fn new(config Config) !&Picoev {
304304
listening_socket_fd := listen(config) or {
305305
elog('Error during listen: ${err}')
@@ -340,7 +340,7 @@ pub fn new(config Config) !&Picoev {
340340
return pv
341341
}
342342

343-
// serve starts the event loop for accepting new connections
343+
// serve starts the event loop for accepting new connections.
344344
// See also picoev.new().
345345
pub fn (mut pv Picoev) serve() {
346346
spawn update_date_string(mut pv)
@@ -349,7 +349,7 @@ pub fn (mut pv Picoev) serve() {
349349
}
350350
}
351351

352-
// update_date updates the date field of the Picoev instance every second for HTTP headers
352+
// update_date updates the date field of the Picoev instance every second for HTTP headers.
353353
fn update_date_string(mut pv Picoev) {
354354
for {
355355
// get GMT (UTC) time for the HTTP Date header

vlib/picoev/socket_util.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn fatal_socket_error(fd int) bool {
8787
return true
8888
}
8989

90-
// listen creates a listening tcp socket and returns its file descriptor
90+
// listen creates a listening tcp socket and returns its file descriptor.
9191
fn listen(config Config) !int {
9292
// not using the `net` modules sockets, because not all socket options are defined
9393
fd := C.socket(config.family, net.SocketType.tcp, 0)

0 commit comments

Comments
 (0)