...
Source file
src/net/splice_linux.go
Documentation: net
1
2
3
4
5 package net
6
7 import (
8 "internal/poll"
9 "io"
10 )
11
12
13
14
15
16
17 func spliceFrom(c *netFD, r io.Reader) (written int64, err error, handled bool) {
18 var remain int64 = 1<<63 - 1
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 switch v := r.(type) {
29 case *TCPConn:
30 s = v.fd
31 case tcpConnWithoutWriteTo:
32 s = v.fd
33 case *UnixConn:
34 if v.fd.net != "unix" {
35 return 0, nil, false
36 }
37 s = v.fd
38 default:
39 return 0, nil, false
40 }
41
42 written, handled, sc, err := poll.Splice(&c.pfd, &s.pfd, remain)
43 if lr != nil {
44 lr.N -= written
45 }
46 return written, wrapSyscallError(sc, err), handled
47 }
48
49
50
51
52
53
54 func spliceTo(w io.Writer, c *netFD) (written int64, err error, handled bool) {
55 uc, ok := w.(*UnixConn)
56 if !ok || uc.fd.net != "unix" {
57 return
58 }
59
60 written, handled, sc, err := poll.Splice(&uc.fd.pfd, &c.pfd, 1<<63-1)
61 return written, wrapSyscallError(sc, err), handled
62 }
63
View as plain text