LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package net | 5 package net |
6 | 6 |
7 import ( | 7 import ( |
8 "io" | 8 "io" |
9 "os" | 9 "os" |
10 "syscall" | 10 "syscall" |
11 ) | 11 ) |
12 | |
13 // maxSendfileSize is the largest chunk size we ask the kernel to copy | |
14 // at a time. | |
15 //const maxSendfileSize uint32 = 0x7fffffff | |
16 const maxSendfileSize uint32 = 0x000fffff | |
17 | 12 |
18 type sendfileOp struct { | 13 type sendfileOp struct { |
19 anOp | 14 anOp |
20 src int32 // source | 15 src int32 // source |
21 n uint32 | 16 n uint32 |
22 } | 17 } |
23 | 18 |
24 func (o *sendfileOp) Submit() (errno int) { | 19 func (o *sendfileOp) Submit() (errno int) { |
25 return syscall.TransmitFile(int32(o.fd.sysfd), o.src, o.n, 0, &o.o, nil,
syscall.TF_WRITE_BEHIND) | 20 return syscall.TransmitFile(int32(o.fd.sysfd), o.src, o.n, 0, &o.o, nil,
syscall.TF_WRITE_BEHIND) |
26 } | 21 } |
(...skipping 29 matching lines...) Expand all Loading... |
56 c.wio.Lock() | 51 c.wio.Lock() |
57 defer c.wio.Unlock() | 52 defer c.wio.Unlock() |
58 c.incref() | 53 c.incref() |
59 defer c.decref() | 54 defer c.decref() |
60 | 55 |
61 var o sendfileOp | 56 var o sendfileOp |
62 o.Init(c) | 57 o.Init(c) |
63 o.n = uint32(n) | 58 o.n = uint32(n) |
64 o.src = int32(f.Fd()) | 59 o.src = int32(f.Fd()) |
65 done, err := iosrv.ExecIO(&o, 0) | 60 done, err := iosrv.ExecIO(&o, 0) |
| 61 if err != nil { |
| 62 return 0, err, false |
| 63 } |
66 if lr != nil { | 64 if lr != nil { |
67 lr.N -= int64(done) | 65 lr.N -= int64(done) |
68 } | 66 } |
69 » return int64(done), err, done > 0 | 67 » return int64(done), nil, true |
70 } | 68 } |
LEFT | RIGHT |