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

//go:build linux || (darwin && !ios) || dragonfly || freebsd || solaris || windows

package net

import (
	
	
	
)

// sendFile copies the contents of r to c using the sendfile
// system call to minimize copies.
//
// if handled == true, sendFile returns the number (potentially zero) of bytes
// copied and any non-EOF error.
//
// if handled == false, sendFile performed no work.
func sendFile( *netFD,  io.Reader) ( int64,  error,  bool) {
	if !supportsSendfile() {
		return 0, nil, false
	}
	var  int64 = 0 // 0 writes the entire file
	,  := .(*io.LimitedReader)
	if  {
		,  = .N, .R
		if  <= 0 {
			return 0, nil, true
		}
	}
	// r might be an *os.File or an os.fileWithoutWriteTo.
	// Type assert to an interface rather than *os.File directly to handle the latter case.
	,  := .(syscall.Conn)
	if ! {
		return 0, nil, false
	}

	,  := .SyscallConn()
	if  != nil {
		return 0, nil, false
	}

	var  error
	 = .Read(func( uintptr) bool {
		, ,  = poll.SendFile(&.pfd, , )
		return true
	})
	if  == nil {
		 = 
	}

	if  != nil {
		.N =  - 
	}

	return , wrapSyscallError("sendfile", ), 
}