Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 package net | |
6 | |
7 import ( | |
8 "io" | |
9 "os" | |
10 "syscall" | |
11 ) | |
12 | |
13 type sendfileOp struct { | |
14 anOp | |
15 src int32 // source | |
16 n uint32 | |
17 } | |
18 | |
19 func (o *sendfileOp) Submit() (errno int) { | |
20 return syscall.TransmitFile(int32(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 os.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) | |
58 o.n = uint32(n) | |
59 o.src = int32(f.Fd()) | |
60 done, err := iosrv.ExecIO(&o, 0) | |
brainman
2011/06/07 06:17:54
Sorry I didn't noticed earlier. You should, probab
mattn
2011/06/07 06:27:25
Done.
| |
61 if lr != nil { | |
62 lr.N -= int64(done) | |
63 } | |
64 return int64(done), err, done > 0 | |
brainman
2011/06/07 06:17:54
Then this could change to:
return int64(done), ni
mattn
2011/06/07 06:27:25
Done.
| |
65 } | |
OLD | NEW |