mirror of
https://github.com/golang/go
synced 2024-09-29 07:24:32 -06:00
update poll.SendFile to return 'handled' value, which is true if SendFile did work or no work was necessary (src returned 0 bytes)
This commit is contained in:
parent
7e137f20db
commit
3a50be4f16
@ -11,18 +11,21 @@ import "syscall"
|
|||||||
const maxSendfileSize int = 4 << 20
|
const maxSendfileSize int = 4 << 20
|
||||||
|
|
||||||
// SendFile wraps the sendfile system call.
|
// SendFile wraps the sendfile system call.
|
||||||
func SendFile(dstFD *FD, src int, remain int64) (int64, error) {
|
func SendFile(dstFD *FD, src int, remain int64) (int64, error, bool) {
|
||||||
if err := dstFD.writeLock(); err != nil {
|
if err := dstFD.writeLock(); err != nil {
|
||||||
return 0, err
|
return 0, err, false
|
||||||
}
|
}
|
||||||
defer dstFD.writeUnlock()
|
defer dstFD.writeUnlock()
|
||||||
if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil {
|
if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil {
|
||||||
return 0, err
|
return 0, err, false
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := dstFD.Sysfd
|
dst := dstFD.Sysfd
|
||||||
var written int64
|
var (
|
||||||
var err error
|
written int64
|
||||||
|
err error
|
||||||
|
handled = true
|
||||||
|
)
|
||||||
for remain > 0 {
|
for remain > 0 {
|
||||||
n := maxSendfileSize
|
n := maxSendfileSize
|
||||||
if int64(n) > remain {
|
if int64(n) > remain {
|
||||||
@ -48,8 +51,9 @@ func SendFile(dstFD *FD, src int, remain int64) (int64, error) {
|
|||||||
// support) and syscall.EINVAL (fd types which
|
// support) and syscall.EINVAL (fd types which
|
||||||
// don't implement sendfile)
|
// don't implement sendfile)
|
||||||
err = err1
|
err = err1
|
||||||
|
handled = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return written, err
|
return written, err, handled
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
// sendFile copies the contents of r to c using the sendfile
|
// sendFile copies the contents of r to c using the sendfile
|
||||||
// system call to minimize copies.
|
// system call to minimize copies.
|
||||||
//
|
//
|
||||||
// if handled == true, sendFile returns the number of bytes copied and any
|
// if handled == true, sendFile returns the number (potentially zero) of bytes
|
||||||
// non-EOF error.
|
// copied and any non-EOF error.
|
||||||
//
|
//
|
||||||
// if handled == false, sendFile performed no work.
|
// if handled == false, sendFile performed no work.
|
||||||
func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
|
func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
|
||||||
@ -39,7 +39,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
|
|||||||
|
|
||||||
var werr error
|
var werr error
|
||||||
err = sc.Read(func(fd uintptr) bool {
|
err = sc.Read(func(fd uintptr) bool {
|
||||||
written, werr = poll.SendFile(&c.pfd, int(fd), remain)
|
written, werr, handled = poll.SendFile(&c.pfd, int(fd), remain)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -49,5 +49,5 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
|
|||||||
if lr != nil {
|
if lr != nil {
|
||||||
lr.N = remain - written
|
lr.N = remain - written
|
||||||
}
|
}
|
||||||
return written, wrapSyscallError("sendfile", err), err == nil
|
return written, wrapSyscallError("sendfile", err), handled
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user