mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
veb: support sendfile() syscall on FreeBSD (#21541)
This commit is contained in:
parent
458aab4820
commit
9997ac4367
4 changed files with 26 additions and 2 deletions
12
vlib/veb/sendfile_freebsd.c.v
Normal file
12
vlib/veb/sendfile_freebsd.c.v
Normal 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
|
||||
}
|
|
@ -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 {
|
||||
|
|
12
vlib/x/vweb/sendfile_freebsd.c.v
Normal file
12
vlib/x/vweb/sendfile_freebsd.c.v
Normal 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
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue