OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [sendfile_windows.go] - Blame information for rev 848

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package net
6
 
7
import (
8
        "io"
9
        "os"
10
        "syscall"
11
)
12
 
13
type sendfileOp struct {
14
        anOp
15
        src syscall.Handle // source
16
        n   uint32
17
}
18
 
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)
21
}
22
 
23
func (o *sendfileOp) Name() string {
24
        return "TransmitFile"
25
}
26
 
27
// sendFile copies the contents of r to c using the TransmitFile
28
// system call to minimize copies.
29
//
30
// if handled == true, sendFile returns the number of bytes copied and any
31
// non-EOF error.
32
//
33
// if handled == false, sendFile performed no work.
34
//
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
38
 
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
44
                }
45
        }
46
        f, ok := r.(*os.File)
47
        if !ok {
48
                return 0, nil, false
49
        }
50
 
51
        c.wio.Lock()
52
        defer c.wio.Unlock()
53
        c.incref()
54
        defer c.decref()
55
 
56
        var o sendfileOp
57
        o.Init(c, 'w')
58
        o.n = uint32(n)
59
        o.src = f.Fd()
60
        done, err := iosrv.ExecIO(&o, 0)
61
        if err != nil {
62
                return 0, err, false
63
        }
64
        if lr != nil {
65
                lr.N -= int64(done)
66
        }
67
        return int64(done), nil, true
68
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.