Commit 9ab6ad5b authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Do not run loop in go-routine, but let caller decide.

parent 2dff88ce
...@@ -26,9 +26,9 @@ func main() { ...@@ -26,9 +26,9 @@ func main() {
state.Debug = *debug state.Debug = *debug
mountPoint := flag.Arg(1) mountPoint := flag.Arg(1)
state.Mount(mountPoint, *threaded) state.Mount(mountPoint)
fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug) fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug)
state.Loop(*threaded)
} }
...@@ -72,12 +72,15 @@ func (self *testCase) Setup(t *testing.T) { ...@@ -72,12 +72,15 @@ func (self *testCase) Setup(t *testing.T) {
fs := fuse.NewPathFileSystemConnector(NewPassThroughFuse(self.origDir)) fs := fuse.NewPathFileSystemConnector(NewPassThroughFuse(self.origDir))
self.state = fuse.NewMountState(fs) self.state = fuse.NewMountState(fs)
self.state.Mount(self.mountPoint, false) self.state.Mount(self.mountPoint)
//self.state.Debug = false //self.state.Debug = false
self.state.Debug = true self.state.Debug = true
fmt.Println("Orig ", self.origDir, " mount ", self.mountPoint) fmt.Println("Orig ", self.origDir, " mount ", self.mountPoint)
// Unthreaded, but in background.
go self.state.Loop(false)
} }
// Unmount and del. // Unmount and del.
......
...@@ -99,15 +99,20 @@ func (self *MountState) UnregisterDir(handle uint64) { ...@@ -99,15 +99,20 @@ func (self *MountState) UnregisterDir(handle uint64) {
// using channels. // using channels.
// //
// TODO - error handling should perhaps be user-serviceable. // TODO - error handling should perhaps be user-serviceable.
func (self *MountState) Mount(mountPoint string, threaded bool) os.Error { func (self *MountState) Mount(mountPoint string) os.Error {
file, mp, err := mount(mountPoint) file, mp, err := mount(mountPoint)
if err != nil { if err != nil {
return err return err
} }
self.mountPoint = mp self.mountPoint = mp
self.mountFile = file self.mountFile = file
return nil
}
// Normally, callers should run loop() and wait for FUSE to exit, but
// tests will want to run this in a goroutine.
func (self *MountState) Loop(threaded bool) {
self.threaded = threaded self.threaded = threaded
if self.threaded { if self.threaded {
self.outputChannel = make(chan [][]byte, 100) self.outputChannel = make(chan [][]byte, 100)
self.errorChannel = make(chan os.Error, 100) self.errorChannel = make(chan os.Error, 100)
...@@ -115,8 +120,12 @@ func (self *MountState) Mount(mountPoint string, threaded bool) os.Error { ...@@ -115,8 +120,12 @@ func (self *MountState) Mount(mountPoint string, threaded bool) os.Error {
go self.DefaultErrorHandler() go self.DefaultErrorHandler()
} }
go self.loop() self.loop()
return nil
if self.threaded {
close(self.outputChannel)
close(self.errorChannel)
}
} }
func (self *MountState) Unmount() os.Error { func (self *MountState) Unmount() os.Error {
...@@ -130,7 +139,7 @@ func (self *MountState) Unmount() os.Error { ...@@ -130,7 +139,7 @@ func (self *MountState) Unmount() os.Error {
func (self *MountState) DefaultErrorHandler() { func (self *MountState) DefaultErrorHandler() {
for err := range self.errorChannel { for err := range self.errorChannel {
if err == os.EOF { if err == os.EOF || err == nil {
break break
} }
log.Println("error: ", err) log.Println("error: ", err)
...@@ -223,10 +232,6 @@ func (self *MountState) loop() { ...@@ -223,10 +232,6 @@ func (self *MountState) loop() {
} }
self.mountFile.Close() self.mountFile.Close()
if self.threaded {
close(self.outputChannel)
close(self.errorChannel)
}
} }
func (self *MountState) handle(in_data []byte) { func (self *MountState) handle(in_data []byte) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment