Skip to content

Commit 73cc802

Browse files
committed
fashttp: fixes
1 parent 1bf1abd commit 73cc802

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

vlib/fasthttp/fasthttp_darwin.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// fasthttp_darwin.v
21
module fasthttp
32

43
#include <sys/event.h>

vlib/fasthttp/fasthttp_linux.v

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module fasthttp
66
const epoll_ctl_add = 1
77
const epoll_ctl_del = 2
88
const epoll_ctl_mod = 3
9-
const epoll_in = 1
10-
const epoll_out = 4
11-
const epoll_err = 8
12-
const epoll_hup = 16
13-
const epoll_rdhup = 8192
9+
const epoll_in = 1
10+
const epoll_out = 4
11+
const epoll_err = 8
12+
const epoll_hup = 16
13+
const epoll_rdhup = 8192
1414

1515
union C.epoll_data {
1616
mut:
@@ -69,14 +69,16 @@ fn (mut s Server) process_dones() {
6969
if c.write_pos < c.write_len {
7070
// Not all data sent, add WRITE event
7171
// Note: The connection was removed from epoll before sending to worker, so we ADD here.
72-
control_epoll(s.poll_fd, epoll_ctl_add, c.fd, u32(epoll_out | epoll_rdhup), c)
72+
control_epoll(s.poll_fd, epoll_ctl_add, c.fd, u32(epoll_out | epoll_rdhup),
73+
c)
7374
} else {
7475
// Response sent, re-enable reading for keep-alive
7576
C.free(c.write_buf)
7677
c.write_buf = unsafe { nil }
77-
78+
7879
// Note: The connection was removed from epoll before sending to worker, so we ADD here.
79-
control_epoll(s.poll_fd, epoll_ctl_add, c.fd, u32(epoll_in | epoll_rdhup), c)
80+
control_epoll(s.poll_fd, epoll_ctl_add, c.fd, u32(epoll_in | epoll_rdhup),
81+
c)
8082
c.read_len = 0
8183
}
8284
unsafe { C.free(d) }
@@ -135,7 +137,8 @@ pub fn (mut s Server) run() ! {
135137
C.fcntl(s.worker_data.wake_pipe[1], C.F_SETFL, C.O_NONBLOCK)
136138

137139
// Add wake pipe to epoll
138-
control_epoll(s.poll_fd, epoll_ctl_add, s.worker_data.wake_pipe[0], u32(epoll_in), voidptr(isize(s.worker_data.wake_pipe[0])))
140+
control_epoll(s.poll_fd, epoll_ctl_add, s.worker_data.wake_pipe[0], u32(epoll_in),
141+
voidptr(isize(s.worker_data.wake_pipe[0])))
139142

140143
// Create worker threads
141144
for i := 0; i < num_threads; i++ {
@@ -167,10 +170,11 @@ pub fn (mut s Server) run() ! {
167170
C.memset(new_c, 0, sizeof(Conn))
168171
new_c.fd = client_fd
169172
C.fcntl(new_c.fd, C.F_SETFL, C.O_NONBLOCK)
170-
171-
control_epoll(s.poll_fd, epoll_ctl_add, new_c.fd, u32(epoll_in | epoll_rdhup), new_c)
173+
174+
control_epoll(s.poll_fd, epoll_ctl_add, new_c.fd, u32(epoll_in | epoll_rdhup),
175+
new_c)
172176
continue
173-
}
177+
}
174178

175179
// 2. Check for Wake Pipe (Worker finished a task)
176180
if ptr_val == s.worker_data.wake_pipe[0] {
@@ -255,7 +259,6 @@ pub fn (mut s Server) run() ! {
255259
s.worker_data.task_tail = t
256260
C.pthread_cond_signal(&s.worker_data.task_cond)
257261
C.pthread_mutex_unlock(&s.worker_data.task_mutex)
258-
259262
} else if (event.events & u32(epoll_out)) != 0 { // Handle Write
260263
write_ptr := unsafe { &u8(c.write_buf) + c.write_pos }
261264
written := C.write(c.fd, write_ptr, c.write_len - c.write_pos)
@@ -270,7 +273,8 @@ pub fn (mut s Server) run() ! {
270273
C.free(c.write_buf)
271274
c.write_buf = unsafe { nil }
272275
// Done writing, modify epoll to stop listening for OUT and start listening for IN
273-
control_epoll(s.poll_fd, epoll_ctl_mod, c.fd, u32(epoll_in | epoll_rdhup), c)
276+
control_epoll(s.poll_fd, epoll_ctl_mod, c.fd, u32(epoll_in | epoll_rdhup),
277+
c)
274278
c.read_len = 0
275279
}
276280
}

vlib/fasthttp/fasthttp_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ $if darwin {
4545
server.run() or { eprintln('Server failed to run: ${err}') }
4646
}
4747
}
48+
*/
4849

4950
fn test_x() {
5051
assert true
5152
}
52-
*/

0 commit comments

Comments
 (0)