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