Made the message shrinking API less confusing.

geesefs-0-30-9
Aaron Jacobs 2015-08-10 15:45:46 +10:00
parent 9a7512aac0
commit 81de9fb6cc
2 changed files with 9 additions and 8 deletions

View File

@ -448,7 +448,7 @@ func (c *Connection) kernelResponse(
// 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
// header.
m.Shrink(uintptr(m.Len() - int(buffer.OutMessageInitialSize)))
m.ShrinkTo(buffer.OutMessageInitialSize)
}
// 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
// of the out message. We need only shrink to the right size based on how
// much the user read.
m.Shrink(uintptr(m.Len() - (int(buffer.OutMessageInitialSize) + o.BytesRead)))
m.ShrinkTo(buffer.OutMessageInitialSize + uintptr(o.BytesRead))
case *fuseops.ReleaseDirHandleOp:
// Empty response
@ -539,7 +539,7 @@ func (c *Connection) kernelResponseForOp(
// 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
// much the user read.
m.Shrink(uintptr(m.Len() - (int(buffer.OutMessageInitialSize) + o.BytesRead)))
m.ShrinkTo(buffer.OutMessageInitialSize + uintptr(o.BytesRead))
case *fuseops.WriteFileOp:
out := (*fusekernel.WriteOut)(m.Grow(unsafe.Sizeof(fusekernel.WriteOut{})))

View File

@ -90,13 +90,14 @@ func (b *OutMessage) GrowNoZero(size uintptr) (p unsafe.Pointer) {
return
}
// Throw away the last n bytes. Panics if n is out of range.
func (b *OutMessage) Shrink(n uintptr) {
if n > b.offset-OutMessageInitialSize {
panic(fmt.Sprintf("Shrink(%d) out of range for offset %d", n, b.offset))
// Shrink to the supplied size. Panic if the size is greater than Len() or less
// than OutMessageInitialSize.
func (b *OutMessage) ShrinkTo(n uintptr) {
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