Made Server an interface, for expandability.

geesefs-0-30-9
Aaron Jacobs 2015-03-24 16:08:42 +11:00
parent fb40c200a9
commit cfc692da07
2 changed files with 8 additions and 7 deletions

View File

@ -22,9 +22,11 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// A Server is a function that reads ops from the supplied Connection, // A type that knows how to serve ops read from a connection.
// responding to them as appropriate. type Server interface {
type Server func(*Connection) // Read and serve ops from the supplied connection until EOF.
ServeOps(*Connection)
}
// A struct representing the status of a mount operation, with a method that // A struct representing the status of a mount operation, with a method that
// waits for unmounting. // waits for unmounting.
@ -130,7 +132,7 @@ func Mount(
// Serve the connection in the background. When done, set the join status. // Serve the connection in the background. When done, set the join status.
go func() { go func() {
server(connection) server.ServeOps(connection)
mfs.joinStatus = connection.close() mfs.joinStatus = connection.close()
close(mfs.joinStatusAvailable) close(mfs.joinStatusAvailable)
}() }()

View File

@ -33,11 +33,10 @@ import (
// //
// Each file contains the string "Hello, world!". // Each file contains the string "Hello, world!".
func NewHelloFS(clock timeutil.Clock) (server fuse.Server, err error) { func NewHelloFS(clock timeutil.Clock) (server fuse.Server, err error) {
fs := &helloFS{ server = &helloFS{
Clock: clock, Clock: clock,
} }
server = fuse.Server(fs.serve)
return return
} }
@ -45,7 +44,7 @@ type helloFS struct {
Clock timeutil.Clock Clock timeutil.Clock
} }
func (fs *helloFS) serve(c *fuse.Connection) { func (fs *helloFS) ServeOps(c *fuse.Connection) {
for { for {
op, err := c.ReadOp() op, err := c.ReadOp()
if err == io.EOF { if err == io.EOF {