libgo: update to Go 1.11
[official-gcc.git] / libgo / go / net / sendfile_windows.go
blobbccd8b149f738e55ce61d406b1400dff25069b6b
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.
22 // Note that sendfile for windows does not support >2GB file.
23 func sendFile(fd *netFD, r io.Reader) (written int64, err error, handled bool) {
24 var n int64 = 0 // by default, copy until EOF
26 lr, ok := r.(*io.LimitedReader)
27 if ok {
28 n, r = lr.N, lr.R
29 if n <= 0 {
30 return 0, nil, true
33 f, ok := r.(*os.File)
34 if !ok {
35 return 0, nil, false
38 done, err := poll.SendFile(&fd.pfd, syscall.Handle(f.Fd()), n)
40 if err != nil {
41 return 0, wrapSyscallError("transmitfile", err), false
43 if lr != nil {
44 lr.N -= int64(done)
46 return int64(done), nil, true