Connection.readMessage
parent
9ea4360f19
commit
f2e8a5d806
|
@ -15,7 +15,6 @@
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
|
@ -215,8 +214,27 @@ func (c *Connection) destroyInMessage(m *buffer.InMessage) {
|
||||||
// Read the next message from the kernel. The message must later be destroyed
|
// Read the next message from the kernel. The message must later be destroyed
|
||||||
// using destroyInMessage.
|
// using destroyInMessage.
|
||||||
func (c *Connection) readMessage() (m *buffer.InMessage, err error) {
|
func (c *Connection) readMessage() (m *buffer.InMessage, err error) {
|
||||||
err = errors.New("TODO")
|
// Allocate a message.
|
||||||
return
|
m = c.allocateInMessage()
|
||||||
|
|
||||||
|
// Loop past transient errors.
|
||||||
|
for {
|
||||||
|
// Lock and read.
|
||||||
|
//
|
||||||
|
// TODO(jacobsa): Ensure that we document concurrency constraints that make
|
||||||
|
// it safe, then kill the lock here.
|
||||||
|
c.wrapped.Rio.RLock()
|
||||||
|
err = m.Init(c.wrapped.Dev)
|
||||||
|
c.wrapped.Rio.RUnlock()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.destroyInMessage(m)
|
||||||
|
m = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the next op from the kernel process. Return io.EOF if the kernel has
|
// Read the next op from the kernel process. Return io.EOF if the kernel has
|
||||||
|
|
|
@ -55,11 +55,22 @@ func (m *InMessage) Init(r io.Reader) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the message is long enough that calling Header is safe.
|
||||||
if uintptr(n) < unsafe.Sizeof(fusekernel.InHeader{}) {
|
if uintptr(n) < unsafe.Sizeof(fusekernel.InHeader{}) {
|
||||||
err = fmt.Errorf("Unexpectedly read only %d bytes.", n)
|
err = fmt.Errorf("Unexpectedly read only %d bytes.", n)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the header's length.
|
||||||
|
if int(m.Header().Len) != n {
|
||||||
|
err = fmt.Errorf(
|
||||||
|
"Header says %d bytes, but we read %d",
|
||||||
|
m.Header().Len,
|
||||||
|
n)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
m.remaining = m.storage[:n]
|
m.remaining = m.storage[:n]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue