Source file
src/os/zero_copy_solaris.go
1
2
3
4
5 package os
6
7 import (
8 "internal/poll"
9 "io"
10 "runtime"
11 "syscall"
12 )
13
14 func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) {
15 return 0, false, nil
16 }
17
18
19 func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
20 var remain int64 = 0
21 lr, ok := r.(*io.LimitedReader)
22 if ok {
23 remain, r = lr.N, lr.R
24 if remain <= 0 {
25 return 0, true, nil
26 }
27 }
28
29 var src *File
30 switch v := r.(type) {
31 case *File:
32 src = v
33 case fileWithoutWriteTo:
34 src = v.File
35 default:
36 return 0, false, nil
37 }
38
39 if src.checkValid("ReadFrom") != nil {
40
41
42 return 0, false, nil
43 }
44
45
46
47
48
49 if f.pfd.Sysfd == src.pfd.Sysfd {
50 return 0, false, nil
51 }
52
53
54
55
56
57 if runtime.GOOS == "illumos" {
58 fi, err := f.Stat()
59 if err != nil {
60 return 0, false, nil
61 }
62 st, ok := fi.Sys().(*syscall.Stat_t)
63 if !ok {
64 return 0, false, nil
65 }
66 if typ := st.Mode & syscall.S_IFMT; typ != syscall.S_IFREG {
67 return 0, false, nil
68 }
69 }
70
71 sc, err := src.SyscallConn()
72 if err != nil {
73 return
74 }
75
76
77
78
79
80 rerr := sc.Read(func(fd uintptr) bool {
81 written, err, handled = poll.SendFile(&f.pfd, int(fd), remain)
82 return true
83 })
84 if lr != nil {
85 lr.N = remain - written
86 }
87 if err == nil {
88 err = rerr
89 }
90
91 return written, handled, wrapSyscallError("sendfile", err)
92 }
93
View as plain text