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 const maxSendfileSize int = 4 << 20
16
17
18 func SendFile(dstFD *FD, src int, pos, remain int64) (int64, error) {
19 if err := dstFD.writeLock(); err != nil {
20 return 0, err
21 }
22 defer dstFD.writeUnlock()
23 if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil {
24 return 0, err
25 }
26
27 dst := dstFD.Sysfd
28 var written int64
29 var err error
30 for remain > 0 {
31 n := maxSendfileSize
32 if int64(n) > remain {
33 n = int(remain)
34 }
35 pos1 := pos
36 n, err1 := syscall.Sendfile(dst, src, &pos1, n)
37 if err1 == syscall.EAGAIN || err1 == syscall.EINTR {
38
39 n = int(pos1 - pos)
40 }
41 if n > 0 {
42 pos += int64(n)
43 written += int64(n)
44 remain -= int64(n)
45 } else if n == 0 && err1 == nil {
46 break
47 }
48 if err1 == syscall.EAGAIN {
49 if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil {
50 continue
51 }
52 }
53 if err1 == syscall.EINTR {
54 continue
55 }
56 if err1 != nil {
57
58
59
60 err = err1
61 break
62 }
63 }
64 return written, err
65 }
66
View as plain text