* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / libgo / go / net / sendfile_windows.go
blob2d64f2f5bff93fe8d98d12a0258e5d872e5dfb41
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 "io"
9 "os"
10 "syscall"
13 type sendfileOp struct {
14 anOp
15 src syscall.Handle // source
16 n uint32
19 func (o *sendfileOp) Submit() (err error) {
20 return syscall.TransmitFile(o.fd.sysfd, o.src, o.n, 0, &o.o, nil, syscall.TF_WRITE_BEHIND)
23 func (o *sendfileOp) Name() string {
24 return "TransmitFile"
27 // sendFile copies the contents of r to c using the TransmitFile
28 // system call to minimize copies.
30 // if handled == true, sendFile returns the number of bytes copied and any
31 // non-EOF error.
33 // if handled == false, sendFile performed no work.
35 // Note that sendfile for windows does not suppport >2GB file.
36 func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
37 var n int64 = 0 // by default, copy until EOF
39 lr, ok := r.(*io.LimitedReader)
40 if ok {
41 n, r = lr.N, lr.R
42 if n <= 0 {
43 return 0, nil, true
46 f, ok := r.(*os.File)
47 if !ok {
48 return 0, nil, false
51 if err := c.incref(false); err != nil {
52 return 0, err, true
54 defer c.decref()
55 c.wio.Lock()
56 defer c.wio.Unlock()
58 var o sendfileOp
59 o.Init(c, 'w')
60 o.n = uint32(n)
61 o.src = syscall.Handle(f.Fd())
62 done, err := iosrv.ExecIO(&o, 0)
63 if err != nil {
64 return 0, err, false
66 if lr != nil {
67 lr.N -= int64(done)
69 return int64(done), nil, true