Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Delta Between Two Patch Sets: src/pkg/net/sendfile_windows.go

Issue 4536076: code review 4536076: net: Sendfile for win32. (Closed)
Left Patch Set: diff -r b683b10bb780 http://go.googlecode.com/hg/ Created 13 years, 10 months ago
Right Patch Set: diff -r 7358615f596c http://go.googlecode.com/hg/ Created 13 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/Makefile ('k') | src/pkg/syscall/syscall_windows.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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)
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b