github.com/ltltlt/go-source-code@v0.0.0-20190830023027-95be009773aa/internal/poll/sendfile_windows.go (about) 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 ft, err := syscall.GetFileType(src) 12 if err != nil { 13 return 0, err 14 } 15 // TransmitFile does not work with pipes 16 if ft == syscall.FILE_TYPE_PIPE { 17 return 0, syscall.ESPIPE 18 } 19 20 if err := fd.writeLock(); err != nil { 21 return 0, err 22 } 23 defer fd.writeUnlock() 24 25 o := &fd.wop 26 o.qty = uint32(n) 27 o.handle = src 28 done, err := wsrv.ExecIO(o, func(o *operation) error { 29 return syscall.TransmitFile(o.fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND) 30 }) 31 return int64(done), err 32 }