diff --git a/vlib/picoev/loop_default.c.v b/vlib/picoev/loop_default.c.v index 685dc02283..55ce785394 100644 --- a/vlib/picoev/loop_default.c.v +++ b/vlib/picoev/loop_default.c.v @@ -76,13 +76,14 @@ fn (mut pv Picoev) poll_once(max_wait_in_sec int) int { // Iterates through file descriptors and calls their callbacks for triggered events for target in pv.file_descriptors { if target.loop_id == pv.loop.id { - // vfmt off - read_events := ( - (if C.FD_ISSET(target.fd, &readfds) != 0 { picoev_read } else { 0 }) - | - (if C.FD_ISSET(target.fd, &writefds) != 0 { picoev_write } else { 0 }) - ) - // vfmt on + mut read_events := 0 + if C.FD_ISSET(target.fd, &readfds) != 0 { + read_events |= picoev_read + } + if C.FD_ISSET(target.fd, &writefds) != 0 { + read_events |= picoev_write + } + if read_events != 0 { $if trace_fd ? { eprintln('do callback ${target.fd}') diff --git a/vlib/picoev/loop_freebsd.c.v b/vlib/picoev/loop_freebsd.c.v index 139756f4ed..5700f8233a 100644 --- a/vlib/picoev/loop_freebsd.c.v +++ b/vlib/picoev/loop_freebsd.c.v @@ -51,13 +51,15 @@ pub fn create_kqueue_loop(id int) !&KqueueLoop { // ev_set sets a new `kevent` with file descriptor `index` @[inline] pub fn (mut pv Picoev) ev_set(index int, operation int, events int) { - // vfmt off - filter := i16( - (if events & picoev_read != 0 { C.EVFILT_READ } else { 0 }) - | - (if events & picoev_write != 0 { C.EVFILT_WRITE } else { 0 }) - ) - // vfmt on + mut filter := 0 + if events & picoev_read != 0 { + filter |= C.EVFILT_READ + } + if events & picoev_write != 0 { + filter |= C.EVFILT_WRITE + } + filter = i16(filter) + C.EV_SET(&pv.loop.changelist[index], pv.loop.changed_fds, filter, operation, 0, 0, 0) } diff --git a/vlib/picoev/loop_linux.c.v b/vlib/picoev/loop_linux.c.v index 36add2e587..e8b9a6363b 100644 --- a/vlib/picoev/loop_linux.c.v +++ b/vlib/picoev/loop_linux.c.v @@ -116,13 +116,14 @@ fn (mut pv Picoev) poll_once(max_wait_in_sec int) int { assert event.data.fd < max_fds } if pv.loop.id == target.loop_id && target.events & picoev_readwrite != 0 { - // vfmt off - read_events := ( - (if event.events & u32(C.EPOLLIN) != 0 { picoev_read } else { 0 }) - | - (if event.events & u32(C.EPOLLOUT) != 0 { picoev_write } else { 0 }) - ) - // vfmt on + mut read_events := 0 + if event.events & u32(C.EPOLLIN) != 0 { + read_events |= picoev_read + } + if event.events & u32(C.EPOLLOUT) != 0 { + read_events |= picoev_write + } + if read_events != 0 { // do callback! unsafe { target.cb(event.data.fd, read_events, &pv) } diff --git a/vlib/picoev/loop_macos.c.v b/vlib/picoev/loop_macos.c.v index 139756f4ed..5700f8233a 100644 --- a/vlib/picoev/loop_macos.c.v +++ b/vlib/picoev/loop_macos.c.v @@ -51,13 +51,15 @@ pub fn create_kqueue_loop(id int) !&KqueueLoop { // ev_set sets a new `kevent` with file descriptor `index` @[inline] pub fn (mut pv Picoev) ev_set(index int, operation int, events int) { - // vfmt off - filter := i16( - (if events & picoev_read != 0 { C.EVFILT_READ } else { 0 }) - | - (if events & picoev_write != 0 { C.EVFILT_WRITE } else { 0 }) - ) - // vfmt on + mut filter := 0 + if events & picoev_read != 0 { + filter |= C.EVFILT_READ + } + if events & picoev_write != 0 { + filter |= C.EVFILT_WRITE + } + filter = i16(filter) + C.EV_SET(&pv.loop.changelist[index], pv.loop.changed_fds, filter, operation, 0, 0, 0) }