// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package pollimport// maxSendfileSize is the largest chunk size we ask the kernel to copy// at a time.const maxSendfileSize int = 4 << 20// SendFile wraps the sendfile system call.func ( *FD, int, int64) ( int64, error, bool) {deferfunc() {TestHookDidSendFile(, , , , ) }()if := .writeLock(); != nil {return0, , false }defer .writeUnlock()if := .pd.prepareWrite(.isFile); != nil {return0, , false } := .Sysfdfor > 0 { := maxSendfileSizeifint64() > { = int() } , = syscall.Sendfile(, , nil, )if > 0 { += int64() -= int64()continue } elseif != syscall.EAGAIN && != syscall.EINTR {// This includes syscall.ENOSYS (no kernel // support) and syscall.EINVAL (fd types which // don't implement sendfile), and other errors. // We should end the loop when there is no error // returned from sendfile(2) or it is not a retryable error.break }if == syscall.EINTR {continue }if = .pd.waitWrite(.isFile); != nil {break } } = != 0 || ( != syscall.ENOSYS && != syscall.EINVAL)return}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.