Made the message shrinking API less confusing.
parent
9a7512aac0
commit
81de9fb6cc
|
@ -448,7 +448,7 @@ func (c *Connection) kernelResponse(
|
||||||
// the header, because on OS X the kernel otherwise returns EINVAL when we
|
// the header, because on OS X the kernel otherwise returns EINVAL when we
|
||||||
// attempt to write an error response with a length that extends beyond the
|
// attempt to write an error response with a length that extends beyond the
|
||||||
// header.
|
// header.
|
||||||
m.Shrink(uintptr(m.Len() - int(buffer.OutMessageInitialSize)))
|
m.ShrinkTo(buffer.OutMessageInitialSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, fill in the rest of the response.
|
// Otherwise, fill in the rest of the response.
|
||||||
|
@ -522,7 +522,7 @@ func (c *Connection) kernelResponseForOp(
|
||||||
// convertInMessage already set up the destination buffer to be at the end
|
// convertInMessage already set up the destination buffer to be at the end
|
||||||
// of the out message. We need only shrink to the right size based on how
|
// of the out message. We need only shrink to the right size based on how
|
||||||
// much the user read.
|
// much the user read.
|
||||||
m.Shrink(uintptr(m.Len() - (int(buffer.OutMessageInitialSize) + o.BytesRead)))
|
m.ShrinkTo(buffer.OutMessageInitialSize + uintptr(o.BytesRead))
|
||||||
|
|
||||||
case *fuseops.ReleaseDirHandleOp:
|
case *fuseops.ReleaseDirHandleOp:
|
||||||
// Empty response
|
// Empty response
|
||||||
|
@ -539,7 +539,7 @@ func (c *Connection) kernelResponseForOp(
|
||||||
// convertInMessage already set up the destination buffer to be at the end
|
// convertInMessage already set up the destination buffer to be at the end
|
||||||
// of the out message. We need only shrink to the right size based on how
|
// of the out message. We need only shrink to the right size based on how
|
||||||
// much the user read.
|
// much the user read.
|
||||||
m.Shrink(uintptr(m.Len() - (int(buffer.OutMessageInitialSize) + o.BytesRead)))
|
m.ShrinkTo(buffer.OutMessageInitialSize + uintptr(o.BytesRead))
|
||||||
|
|
||||||
case *fuseops.WriteFileOp:
|
case *fuseops.WriteFileOp:
|
||||||
out := (*fusekernel.WriteOut)(m.Grow(unsafe.Sizeof(fusekernel.WriteOut{})))
|
out := (*fusekernel.WriteOut)(m.Grow(unsafe.Sizeof(fusekernel.WriteOut{})))
|
||||||
|
|
|
@ -90,13 +90,14 @@ func (b *OutMessage) GrowNoZero(size uintptr) (p unsafe.Pointer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throw away the last n bytes. Panics if n is out of range.
|
// Shrink to the supplied size. Panic if the size is greater than Len() or less
|
||||||
func (b *OutMessage) Shrink(n uintptr) {
|
// than OutMessageInitialSize.
|
||||||
if n > b.offset-OutMessageInitialSize {
|
func (b *OutMessage) ShrinkTo(n uintptr) {
|
||||||
panic(fmt.Sprintf("Shrink(%d) out of range for offset %d", n, b.offset))
|
if n < OutMessageInitialSize || n > b.offset {
|
||||||
|
panic(fmt.Sprintf("ShrinkTo(%d) out of range for offset %d", n, b.offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
b.offset -= n
|
b.offset = n
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equivalent to growing by the length of p, then copying p over the new
|
// Equivalent to growing by the length of p, then copying p over the new
|
||||||
|
|
Loading…
Reference in New Issue