veb: support sendfile() syscall on FreeBSD (#21541)

This commit is contained in:
Bakul Shah 2024-05-20 22:47:24 -07:00 committed by GitHub
parent 458aab4820
commit 9997ac4367
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,12 @@
module veb
fn C.sendfile(in_fd int, out_fd int, offset int, count int, voidptr offsetp, voidptr hdr, flags int) int
fn sendfile(out_fd int, in_fd int, nr_bytes int) int {
// out_fd must be a stream socket descriptor.
r := C.sendfile(in_fd, out_fd, 0, nr_bytes, unsafe { nil }, unsafe { nil }, 0)
if r == 0 {
return nr_bytes
}
return r
}

View file

@ -391,7 +391,7 @@ fn handle_timeout(mut pv picoev.Picoev, mut params RequestParams, fd int) {
fn handle_write_file(mut pv picoev.Picoev, mut params RequestParams, fd int) {
mut bytes_to_write := int(params.file_responses[fd].total - params.file_responses[fd].pos)
$if linux {
$if linux || freebsd {
bytes_written := sendfile(fd, params.file_responses[fd].file.fd, bytes_to_write)
params.file_responses[fd].pos += bytes_written
} $else {

View file

@ -0,0 +1,12 @@
module vweb
fn C.sendfile(in_fd int, out_fd int, offset int, count int, voidptr offsetp, voidptr hdr, flags int) int
fn sendfile(out_fd int, in_fd int, nr_bytes int) int {
// out_fd must be a stream socket descriptor.
r := C.sendfile(in_fd, out_fd, 0, nr_bytes, unsafe { nil }, unsafe { nil }, 0)
if r == 0 {
return nr_bytes
}
return r
}

View file

@ -391,7 +391,7 @@ fn handle_timeout(mut pv picoev.Picoev, mut params RequestParams, fd int) {
fn handle_write_file(mut pv picoev.Picoev, mut params RequestParams, fd int) {
mut bytes_to_write := int(params.file_responses[fd].total - params.file_responses[fd].pos)
$if linux {
$if linux || freebsd {
bytes_written := sendfile(fd, params.file_responses[fd].file.fd, bytes_to_write)
params.file_responses[fd].pos += bytes_written
} $else {