1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 // sendFile copies the contents of r to c using the sendfile
16 // system call to minimize copies.
18 // if handled == true, sendFile returns the number of bytes copied and any
21 // if handled == false, sendFile performed no work.
22 func sendFile(c
*netFD
, r io
.Reader
) (written
int64, err error
, handled
bool) {
23 var remain
int64 = 1 << 62 // by default, copy until EOF
25 lr
, ok
:= r
.(*io
.LimitedReader
)
27 remain
, r
= lr
.N
, lr
.R
37 sc
, err
:= f
.SyscallConn()
43 err
= sc
.Read(func(fd
uintptr) bool {
44 written
, werr
= poll
.SendFile(&c
.pfd
, int(fd
), remain
)
52 lr
.N
= remain
- written
54 return written
, wrapSyscallError("sendfile", err
), written
> 0