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.
9 // maxSendfileSize is the largest chunk size we ask the kernel to copy
11 const maxSendfileSize
int = 4 << 20
13 // SendFile wraps the sendfile system call.
14 func SendFile(dstFD
*FD
, src
int, remain
int64) (int64, error
) {
15 if err
:= dstFD
.writeLock(); err
!= nil {
18 defer dstFD
.writeUnlock()
20 dst
:= int(dstFD
.Sysfd
)
25 if int64(n
) > remain
{
28 n
, err1
:= syscall
.Sendfile(dst
, src
, nil, n
)
33 if n
== 0 && err1
== nil {
36 if err1
== syscall
.EAGAIN
{
37 if err1
= dstFD
.pd
.waitWrite(dstFD
.isFile
); err1
== nil {
42 // This includes syscall.ENOSYS (no kernel
43 // support) and syscall.EINVAL (fd types which
44 // don't implement sendfile)