...
Source file
src/internal/poll/sendfile_solaris.go
1
2
3
4
5 package poll
6
7 import "syscall"
8
9
10
11
12
13
14
15
16 const maxSendfileSize int = 4 << 20
17
18
19 func SendFile(dstFD *FD, src int, pos, remain int64) (int64, error, bool) {
20 if err := dstFD.writeLock(); err != nil {
21 return 0, err, false
22 }
23 defer dstFD.writeUnlock()
24 if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil {
25 return 0, err, false
26 }
27
28 dst := dstFD.Sysfd
29 var (
30 written int64
31 err error
32 handled = true
33 )
34 for remain > 0 {
35 n := maxSendfileSize
36 if int64(n) > remain {
37 n = int(remain)
38 }
39 pos1 := pos
40 n, err1 := syscall.Sendfile(dst, src, &pos1, n)
41 if err1 == syscall.EAGAIN || err1 == syscall.EINTR {
42
43 n = int(pos1 - pos)
44 }
45 if n > 0 {
46 pos += int64(n)
47 written += int64(n)
48 remain -= int64(n)
49 } else if n == 0 && err1 == nil {
50 break
51 }
52 if err1 == syscall.EAGAIN {
53 if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil {
54 continue
55 }
56 }
57 if err1 == syscall.EINTR {
58 continue
59 }
60 if err1 != nil {
61
62
63
64 err = err1
65 handled = false
66 break
67 }
68 }
69 return written, err, handled
70 }
71
View as plain text