Example #1
0
func (ns *Ns) ops(name string, ops ...seq.Req) (*NsFile, []seq.Result, error) {
	sq, replies := seq.NewSequencer()
	c := make(chan []seq.Result)
	go func() {
		r, ok := <-replies
		if !ok {
			//log.Printf("ops got premature eof, seq %p, error %#v", seq, seq.Error())
			c <- nil
			return
		}
		_, ok = <-replies
		if ok {
			panic("expected closed")
		}
		c <- r.(OpResults)
	}()
	f := ns.seqops(sq, name, ops...)
	sq.Do(nil, nil)
	r := <-c
	if err := sq.Wait(); err != nil {
		return nil, r, err
	}
	//log.Printf("ops got eof, chan %p, seq %p, error %#v", replies, seq, seq.Error())
	return f, r, sq.Error()
}
Example #2
0
func cmdread(ns *g9pc.Ns, s []string) {
	sq, results := seq.NewSequencer()
	go func() {
		r := <-results // walk result
		r = <-results  // open result
		r = <-results  // readstream result
		_, ok := <-results
		if ok {
			panic("expected closed")
		}
	}()

	f := ns.SeqWalk(sq, s[0])
	sq.Do(f.File(), seq.OpenReq{g9p.OREAD})
	rd := f.SeqReadStream(sq, 200, 20)

	buf := make([]byte, 10)
	for {
		n, err := rd.Read(buf)
		if n == 0 {
			fmt.Fprintf(os.Stderr, "read error: %v\n", err)
			break
		}
		fmt.Printf("%q\n", buf[0:n])
	}
	rd.Close()
	sq.Do(f.File(), seq.ClunkReq{}) // strictly speaking unnecessary.
	sq.Do(nil, nil)
	sq.Wait()
}
Example #3
0
func (f *NsFile) ReadStream(nreqs, iounit int) io.ReadCloser {
	sq, replies := seq.NewSequencer()
	go func() {
		<-replies // ReadStream
		_, ok := <-replies
		if ok {
			panic("expected eof")
		}
	}()
	return f.SeqReadStream(sq, nreqs, iounit)
}
Example #4
0
func (f *NsFile) Walk(elem ...string) (*NsFile, error) {
	seq, results := seq.NewSequencer()
	go func() {
		<-results // Walk
		_, ok := <-results
		if ok {
			panic("expected closed")
		}
	}()
	f = f.SeqWalk(seq, elem...)
	seq.Do(nil, nil)
	if err := seq.Wait(); err != nil {
		return nil, err
	}
	return f, nil
}
Example #5
0
func (ns *Ns) ReadStream(name string, nreqs, iounit int) io.ReadCloser {
	sq, replies := seq.NewSequencer()
	go func() {
		<-replies // walk
		<-replies // open
		<-replies // stream
		sq.Do(nil, nil)
		_, ok := <-replies
		if ok {
			panic("expected closed")
		}
	}()

	f := ns.SeqWalk(sq, name)
	sq.Do(f.f, seq.OpenReq{plan9.OREAD})
	return f.SeqReadStream(sq, nreqs, iounit)
}
Example #6
0
func (ns *Ns) Create(name string, mode uint8, perm plan9.Perm) (*NsFile, error) {
	sq, replies := seq.NewSequencer()
	go func() {
		<-replies
		_, ok := <-replies
		if ok {
			panic("expected closed")
		}
	}()

	f := ns.SeqCreate(sq, name, mode, perm)
	sq.Do(nil, nil)

	if err := sq.Wait(); err != nil {
		return nil, err
	}
	return f, nil
}
Example #7
0
func (f *NsFile) ops(ops ...seq.Req) ([]seq.Result, error) {
	c := make(chan OpResults)
	seq, replies := seq.NewSequencer()
	go func() {
		r, ok := <-replies
		if !ok {
			c <- nil
		}
		_, ok = <-replies
		if ok {
			panic("expected closed")
		}
		c <- r.(OpResults)
	}()
	f.seqops(seq, ops...)
	seq.Do(nil, nil)
	r := <-c
	return r, seq.Wait()
}
Example #8
0
func (t *traverser) traverse(parent *g9pc.NsFile, path, name string, sync chan bool) {
	sq, results := seq.NewSequencer()
	doneWalk := make(chan bool)
	go func() {
		defer close(doneWalk)
		if name != "" {
			_, ok := <-results // SeqWalk
			if !ok {
				t.printf("cannot walk to %q: %v", path+"/"+name, sq.Error())
				return
			}
		}
		doneWalk <- true
		<-results          // readDir or readFile.
		_, ok := <-results // eof.
		if ok {
			panic("expected closed")
		}
	}()
	fid := parent
	if name != "" {
		fid = parent.SeqWalk(sq, name)
	}
	_, ok := <-doneWalk
	if !ok {
		return
	}
	sync <- true
	t.printf("read %q, dir %v", path+"/"+name, fid.IsDir())
	t.refc <- 1
	go func() {
		t.grab()
		path += "/" + name
		if fid.IsDir() {
			t.readDir(sq, fid, path)
		} else {
			t.readFile(sq, fid, path)
		}
		sq.Do(nil, nil)
		t.refc <- -1
		t.release()
	}()
}
Example #9
0
func (ns *Ns) Walk(name string) (*NsFile, error) {
	sq, results := seq.NewSequencer()
	f, elem := ns.path(name)
	go func() {
		<-results
		_, ok := <-results
		if ok {
			panic("expected closed")
		}
	}()

	f = f.SeqWalk(sq, elem...)
	sq.Do(nil, nil)
	sq.Wait()
	err := sq.Wait()
	if err == nil {
		return f, nil
	}
	return nil, err
}