Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / net / sendfile_windows.go
blob59b1b0d5c1dd85b0cd540f463184ed7295d3ddc8
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.
5 package net
7 import (
8 "internal/poll"
9 "io"
10 "os"
11 "syscall"
14 // sendFile copies the contents of r to c using the TransmitFile
15 // system call to minimize copies.
17 // if handled == true, sendFile returns the number of bytes copied and any
18 // non-EOF error.
20 // if handled == false, sendFile performed no work.
21 func sendFile(fd *netFD, r io.Reader) (written int64, err error, handled bool) {
22 var n int64 = 0 // by default, copy until EOF.
24 lr, ok := r.(*io.LimitedReader)
25 if ok {
26 n, r = lr.N, lr.R
27 if n <= 0 {
28 return 0, nil, true
32 f, ok := r.(*os.File)
33 if !ok {
34 return 0, nil, false
37 written, err = poll.SendFile(&fd.pfd, syscall.Handle(f.Fd()), n)
38 if err != nil {
39 err = wrapSyscallError("transmitfile", err)
42 // If any byte was copied, regardless of any error
43 // encountered mid-way, handled must be set to true.
44 handled = written > 0
46 return