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 var pollSplice = poll.Splice
13
14
15
16
17
18
19 func spliceFrom(c *netFD, r io.Reader) (written int64, err error, handled bool) {
20 var remain int64 = 1<<63 - 1
21 lr, ok := r.(*io.LimitedReader)
22 if ok {
23 remain, r = lr.N, lr.R
24 if remain <= 0 {
25 return 0, nil, true
26 }
27 }
28
29 var s *netFD
30 switch v := r.(type) {
31 case *TCPConn:
32 s = v.fd
33 case tcpConnWithoutWriteTo:
34 s = v.fd
35 case *UnixConn:
36 if v.fd.net != "unix" {
37 return 0, nil, false
38 }
39 s = v.fd
40 default:
41 return 0, nil, false
42 }
43
44 written, handled, err = pollSplice(&c.pfd, &s.pfd, remain)
45 if lr != nil {
46 lr.N -= written
47 }
48 return written, wrapSyscallError("splice", err), handled
49 }
50
51
52
53
54
55
56 func spliceTo(w io.Writer, c *netFD) (written int64, err error, handled bool) {
57 uc, ok := w.(*UnixConn)
58 if !ok || uc.fd.net != "unix" {
59 return
60 }
61
62 written, handled, err = pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
63 return written, wrapSyscallError("splice", err), handled
64 }
65
View as plain text