Source file
src/net/sendfile_unix_alt.go
1
2
3
4
5
6
7 package net
8
9 import (
10 "internal/poll"
11 "io"
12 "syscall"
13 )
14
15 const supportsSendfile = true
16
17
18
19
20
21
22
23
24 func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
25 var remain int64 = 0
26 lr, ok := r.(*io.LimitedReader)
27 if ok {
28 remain, r = lr.N, lr.R
29 if remain <= 0 {
30 return 0, nil, true
31 }
32 }
33
34
35 f, ok := r.(syscall.Conn)
36 if !ok {
37 return 0, nil, false
38 }
39
40 sc, err := f.SyscallConn()
41 if err != nil {
42 return 0, nil, false
43 }
44
45 var werr error
46 err = sc.Read(func(fd uintptr) bool {
47 written, werr, handled = poll.SendFile(&c.pfd, int(fd), remain)
48 return true
49 })
50 if err == nil {
51 err = werr
52 }
53
54 if lr != nil {
55 lr.N = remain - written
56 }
57
58 return written, wrapSyscallError("sendfile", err), handled
59 }
60
View as plain text