Source file
src/os/zero_copy_freebsd.go
1
2
3
4
5 package os
6
7 import (
8 "internal/poll"
9 "io"
10 )
11
12 var pollCopyFileRange = poll.CopyFileRange
13
14 func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) {
15 return 0, false, nil
16 }
17
18 func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
19
20
21
22
23 if f.appendMode {
24 return 0, false, nil
25 }
26
27 var (
28 remain int64
29 lr *io.LimitedReader
30 )
31 if lr, r, remain = tryLimitedReader(r); remain <= 0 {
32 return 0, true, nil
33 }
34
35 var src *File
36 switch v := r.(type) {
37 case *File:
38 src = v
39 case fileWithoutWriteTo:
40 src = v.File
41 default:
42 return 0, false, nil
43 }
44
45 if src.checkValid("ReadFrom") != nil {
46
47
48 return 0, false, nil
49 }
50
51 written, handled, err = pollCopyFileRange(&f.pfd, &src.pfd, remain)
52 if lr != nil {
53 lr.N -= written
54 }
55
56 return written, handled, wrapSyscallError("copy_file_range", err)
57 }
58
View as plain text