Source file
src/net/splice_linux.go
1
2
3
4
5 package net
6
7 import (
8 "internal/poll"
9 "io"
10 )
11
12
13
14
15
16
17 func splice(c *netFD, r io.Reader) (written int64, err error, handled bool) {
18 var remain int64 = 1 << 62
19 lr, ok := r.(*io.LimitedReader)
20 if ok {
21 remain, r = lr.N, lr.R
22 if remain <= 0 {
23 return 0, nil, true
24 }
25 }
26
27 var s *netFD
28 if tc, ok := r.(*TCPConn); ok {
29 s = tc.fd
30 } else if uc, ok := r.(*UnixConn); ok {
31 if uc.fd.net != "unix" {
32 return 0, nil, false
33 }
34 s = uc.fd
35 } else {
36 return 0, nil, false
37 }
38
39 written, handled, sc, err := poll.Splice(&c.pfd, &s.pfd, remain)
40 if lr != nil {
41 lr.N -= written
42 }
43 return written, wrapSyscallError(sc, err), handled
44 }
45
View as plain text