diff --git a/splice/copy.go b/splice/copy.go index e50ca0d1..973d81a6 100644 --- a/splice/copy.go +++ b/splice/copy.go @@ -5,13 +5,28 @@ package splice import ( + "fmt" "io" "os" ) +// NOTE: DEPRECIATED +const ( + FADVISE_NORMAL = 0x0 + FADVISE_RANDOM = 0x1 + FADVISE_SEQUENTIAL = 0x2 + FADVISE_WILLNEED = 0x3 + FADVISE_DONTNEED = 0x4 + FADVISE_NOREUSE = 0x5 +) + func SpliceCopy(dst *os.File, src *os.File, p *Pair) (int64, error) { total := int64(0) - + st, _ := src.Stat() + err := Fadvise64(int(src.Fd()), 0, st.Size(), FADVISE_SEQUENTIAL) + if err != nil { + fmt.Println("Fadvise64 error:", err) + } for { n, err := p.LoadFrom(src.Fd(), p.size) if err != nil { diff --git a/splice/pair_darwin.go b/splice/pair_darwin.go index 19b83b8d..0929977f 100644 --- a/splice/pair_darwin.go +++ b/splice/pair_darwin.go @@ -32,3 +32,7 @@ func (p *Pair) WriteTo(fd uintptr, n int) (int, error) { func (p *Pair) discard() { panic("not implemented") } + +func Fadvise64(fd int, offset int64, length int64, advice int) error { + return nil +} diff --git a/splice/pair_linux.go b/splice/pair_linux.go index b8b183af..6ac9999f 100644 --- a/splice/pair_linux.go +++ b/splice/pair_linux.go @@ -58,3 +58,16 @@ func (p *Pair) discard() { log.Panicf("splicing into /dev/null: %v (close R %d '%v', close W %d '%v')", err, p.r, errR, p.w, errW) } } + +// NOTE: DEPRECIATED +func Fadvise64(fd int, offset int64, length int64, advice int) error { + _, _, errno := syscall.Syscall6(syscall.SYS_FADVISE64, + uintptr(fd), + uintptr(offset), + uintptr(length), + uintptr(advice), 0, 0) + if errno != 0 { + return errno + } + return nil +}