// 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 poll

import 

// 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) {
	if  := .writeLock();  != nil {
		return 0, , false
	}
	defer .writeUnlock()
	if  := .pd.prepareWrite(.isFile);  != nil {
		return 0, , false
	}

	 := .Sysfd
	var (
		 int64
		     error
		 = true
	)
	for  > 0 {
		 := maxSendfileSize
		if int64() >  {
			 = int()
		}
		,  := syscall.Sendfile(, , nil, )
		if  > 0 {
			 += int64()
			 -= int64()
		} else if  == 0 &&  == nil {
			break
		}
		if  == syscall.EINTR {
			continue
		}
		if  == syscall.EAGAIN {
			if  = .pd.waitWrite(.isFile);  == nil {
				continue
			}
		}
		if  != nil {
			// This includes syscall.ENOSYS (no kernel
			// support) and syscall.EINVAL (fd types which
			// don't implement sendfile)
			 = 
			 = false
			break
		}
	}
	return , , 
}