...

Source file src/pkg/internal/poll/sendfile_windows.go

     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 poll
     6	
     7	import "syscall"
     8	
     9	// SendFile wraps the TransmitFile call.
    10	func SendFile(fd *FD, src syscall.Handle, n int64) (int64, error) {
    11		if fd.kind == kindPipe {
    12			// TransmitFile does not work with pipes
    13			return 0, syscall.ESPIPE
    14		}
    15	
    16		if err := fd.writeLock(); err != nil {
    17			return 0, err
    18		}
    19		defer fd.writeUnlock()
    20	
    21		o := &fd.wop
    22		o.qty = uint32(n)
    23		o.handle = src
    24	
    25		// TODO(brainman): skip calling syscall.Seek if OS allows it
    26		curpos, err := syscall.Seek(o.handle, 0, 1)
    27		if err != nil {
    28			return 0, err
    29		}
    30	
    31		o.o.Offset = uint32(curpos)
    32		o.o.OffsetHigh = uint32(curpos >> 32)
    33	
    34		done, err := wsrv.ExecIO(o, func(o *operation) error {
    35			return syscall.TransmitFile(o.fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND)
    36		})
    37		if err == nil {
    38			// Some versions of Windows (Windows 10 1803) do not set
    39			// file position after TransmitFile completes.
    40			// So just use Seek to set file position.
    41			_, err = syscall.Seek(o.handle, curpos+int64(done), 0)
    42		}
    43		return int64(done), err
    44	}
    45	

View as plain text