lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 8434a9645adcf7db17aecfc4299818c13ffaef55
parent 0ea91cffacb137796fdb4a10124134204c6f3693
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 29 Dec 2023 09:01:46 +0900

unexport Req.Ofcal

Diffstat:
Mauth_test.go | 2+-
Mexport_test.go | 2++
Mreq.go | 2+-
Mserver.go | 44++++++++++++++++++++++----------------------
Mserver2_test.go | 28++++++++++++++--------------
Mserver_test.go | 22+++++++++++-----------
6 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/auth_test.go b/auth_test.go @@ -34,7 +34,7 @@ func TestAuth(t *testing.T) { asw.Close() }() runAuth(ctx, t, r.Afid.File.(*lib9p.AuthFile), asr, asw) - r.Ofcall = &lib9p.RAuth{Tag: ifcall.Tag, Aqid: aqid} + r.SetOfcall(&lib9p.RAuth{Tag: ifcall.Tag, Aqid: aqid}) } ctx := context.Background() _, _, err := conn.C.Version(ctx, lib9p.NOTAG, 8*1024, "9P2000") diff --git a/export_test.go b/export_test.go @@ -59,6 +59,8 @@ func (s *Server) SetMSize(size uint32) { s.setMSize(size) } func (r *Req) Ifcall() Msg { return r.ifcall } func (r *Req) SetIfcall(m Msg) { r.ifcall = m } +func (r *Req) Ofcall() Msg { return r.ofcall } +func (r *Req) SetOfcall(m Msg) { r.ofcall = m } func (rp *ReqPool) Add(tag uint16) (*Req, error) { return rp.add(tag) } diff --git a/req.go b/req.go @@ -10,7 +10,7 @@ type Req struct { // Ifcall is incomming 9P message ifcall Msg // Ofcall is response message to Ifcall. - Ofcall Msg + ofcall Msg Fid *Fid Afid *Fid // Oldreq is set with Tflush message. diff --git a/server.go b/server.go @@ -23,7 +23,7 @@ var ( ) func setError(r *Req, err error) { - r.Ofcall = &RError{ + r.ofcall = &RError{ Ename: err, } } @@ -65,7 +65,7 @@ type Server struct { // Auth function is passed an auth request when a TAuth message arrives // If authentication is desired, Auth should - // set Req.Afid.File to an *AuthFile and Req.Ofcall.Qid, and prepare to + // set Req.Afid.File to an *AuthFile and Req.ofcall.Qid, and prepare to // authenticate via the Read()/Write() calls to Req.Afid.File. // Auth should clean up everything it creates when ctx is canceled. // If this is nil, no authentication is performed. @@ -135,17 +135,17 @@ func (s *Server) runResponder(ctx context.Context, rp *ReqPool) { if !ok { return } - r.Ofcall.SetTag(r.tag) + r.ofcall.SetTag(r.tag) // free tag. rp.delete(r.tag) - _, err := s.w.Write(r.Ofcall.marshal()) + _, err := s.w.Write(r.ofcall.marshal()) if err != nil { // TODO: handle error. log.Printf("respond: %v", err) continue } if s.chatty9P { - fmt.Fprintf(os.Stderr, "--> %s\n", r.Ofcall) + fmt.Fprintf(os.Stderr, "--> %s\n", r.ofcall) } case <-ctx.Done(): return @@ -219,11 +219,11 @@ func sVersion(ctx context.Context, s *Server, c <-chan *Req) { if msize > s.mSize() { msize = s.mSize() } - r.Ofcall = &RVersion{ + r.ofcall = &RVersion{ Msize: msize, Version: version, } - s.setMSize(r.Ofcall.(*RVersion).Msize) + s.setMSize(r.ofcall.(*RVersion).Msize) select { case s.respChan <- r: case <-ctx.Done(): @@ -330,7 +330,7 @@ func sAttach(ctx context.Context, s *Server, c <-chan *Req) { r.err = fmt.Errorf("stat root: %v", err) goto resp } - r.Ofcall = &RAttach{ + r.ofcall = &RAttach{ Qid: st.Sys().(*Stat).Qid, } resp: @@ -361,7 +361,7 @@ func sFlush(ctx context.Context, s *Server, c <-chan *Req) { if r.Oldreq != nil { r.Oldreq.flush() } - r.Ofcall = &RFlush{} + r.ofcall = &RFlush{} select { case s.respChan <- r: case <-ctx.Done(): @@ -432,19 +432,19 @@ func sWalk(ctx context.Context, s *Server, c <-chan *Req) { newFid.OMode = -1 newFid.path = cwdp newFid.Uid = oldFid.Uid - r.Ofcall = &RWalk{ + r.ofcall = &RWalk{ Qids: wqids[:n], } resp: - if r.Ofcall == nil { + if r.ofcall == nil { if r.err == nil { - panic("err and r.Ofcall are both nil") + panic("err and r.ofcall are both nil") } setError(r, r.err) s.respChan <- r continue } - ofcall := r.Ofcall.(*RWalk) + ofcall := r.ofcall.(*RWalk) if r.err != nil || len(ofcall.Qids) < len(ifcall.Wnames) { if ifcall.Fid != ifcall.Newfid { s.fPool.delete(ifcall.Newfid) @@ -549,7 +549,7 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) { goto resp } } - r.Ofcall = &ROpen{ + r.ofcall = &ROpen{ Qid: qid, Iounit: s.mSize() - IOHDRSZ, } @@ -656,7 +656,7 @@ func sCreate(ctx context.Context, s *Server, c <-chan *Req) { r.err = fmt.Errorf("stat: %v", err) goto resp } - r.Ofcall = &RCreate{ + r.ofcall = &RCreate{ Qid: st.Sys().(*Stat).Qid, Iounit: s.mSize() - IOHDRSZ, } @@ -771,7 +771,7 @@ func sRead(ctx context.Context, s *Server, c <-chan *Req) { case <-ctx.Done(): return } - r.Ofcall = &RRead{ + r.ofcall = &RRead{ Count: uint32(n), Data: data[:n], } @@ -852,7 +852,7 @@ func sWrite(ctx context.Context, s *Server, c <-chan *Req) { case <-ctx.Done(): return } - r.Ofcall = ofcall + r.ofcall = ofcall resp: if r.err != nil { setError(r, r.err) @@ -888,11 +888,11 @@ func sClunk(ctx context.Context, s *Server, c <-chan *Req) { goto resp } } - r.Ofcall = &RClunk{} + r.ofcall = &RClunk{} resp: if r.err != nil { log.Printf("clunk: %v", r.err) - r.Ofcall = &RClunk{} + r.ofcall = &RClunk{} } select { case s.respChan <- r: @@ -947,7 +947,7 @@ func sRemove(ctx context.Context, s *Server, c <-chan *Req) { r.err = fmt.Errorf("remove: %v", err) goto resp } - r.Ofcall = &RRemove{} + r.ofcall = &RRemove{} resp: if r.err != nil { setError(r, r.err) @@ -985,7 +985,7 @@ func sStat(ctx context.Context, s *Server, c <-chan *Req) { r.err = fmt.Errorf("stat: %v", err) goto resp } - r.Ofcall = &RStat{ + r.ofcall = &RStat{ Stat: fi.Sys().(*Stat), } resp: @@ -1131,7 +1131,7 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) { r.err = fmt.Errorf("wstat: %v", err) goto resp } - r.Ofcall = &RWStat{} + r.ofcall = &RWStat{} resp: if r.err != nil { setError(r, r.err) diff --git a/server2_test.go b/server2_test.go @@ -81,7 +81,7 @@ func TestRunResponder(t *testing.T) { } s.respChan <- &Req{ tag: msg.GetTag(), - Ofcall: msg, + ofcall: msg, } got := make([]byte, len(want)) _, err = io.ReadFull(r, got) @@ -141,13 +141,13 @@ func TestSVersion(t *testing.T) { want *Req }{ {&Req{ifcall: &TVersion{Msize: 1024, Version: "9P2000"}}, - &Req{Ofcall: &RVersion{Msize: 1024, Version: "9P2000"}}}, + &Req{ofcall: &RVersion{Msize: 1024, Version: "9P2000"}}}, {&Req{ifcall: &TVersion{Msize: 564, Version: "9P2000"}}, - &Req{Ofcall: &RVersion{Msize: 564, Version: "9P2000"}}}, + &Req{ofcall: &RVersion{Msize: 564, Version: "9P2000"}}}, {&Req{ifcall: &TVersion{Msize: 8 * 1024, Version: "9P2000"}}, - &Req{Ofcall: &RVersion{Msize: 1024, Version: "9P2000"}}}, + &Req{ofcall: &RVersion{Msize: 1024, Version: "9P2000"}}}, {&Req{ifcall: &TVersion{Msize: 1024, Version: "unko"}}, - &Req{Ofcall: &RVersion{Msize: 1024, Version: "unknown"}}}, + &Req{ofcall: &RVersion{Msize: 1024, Version: "unknown"}}}, } tc := make(chan *Req) rc := make(chan *Req) @@ -159,8 +159,8 @@ func TestSVersion(t *testing.T) { oldMsize := s.msize tc <- test.input ifcall := test.input.ifcall.(*TVersion) - wantmsg := test.want.Ofcall.(*RVersion) - gotmsg := (<-rc).Ofcall.(*RVersion) + wantmsg := test.want.ofcall.(*RVersion) + gotmsg := (<-rc).ofcall.(*RVersion) if !reflect.DeepEqual(wantmsg, gotmsg) { t.Errorf("want: %v,\n\tgot: %v", wantmsg, gotmsg) } @@ -181,14 +181,14 @@ func TestSAuth(t *testing.T) { authFunc func(context.Context, *Req) }{ {&Req{ifcall: &TAuth{Afid: NOFID, Uname: "kenji", Aname: ""}}, - &Req{Ofcall: &RError{Ename: errors.New("authentication not required")}}, nil}, + &Req{ofcall: &RError{Ename: errors.New("authentication not required")}}, nil}, {&Req{ifcall: &TAuth{Afid: NOFID, Uname: "kenji", Aname: ""}}, - &Req{Ofcall: &RError{Ename: errors.New("NOFID can't be used for afid")}}, + &Req{ofcall: &RError{Ename: errors.New("NOFID can't be used for afid")}}, func(ctx context.Context, r *Req) {}}, {&Req{ifcall: &TAuth{Afid: 0, Uname: "kenji", Aname: ""}}, - &Req{Ofcall: &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}}}, + &Req{ofcall: &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}}}, func(ctx context.Context, r *Req) { - r.Ofcall = &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}} + r.ofcall = &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}} }}, } for _, test := range tests { @@ -202,8 +202,8 @@ func TestSAuth(t *testing.T) { defer cancel() go sAuth(ctx, s, tc) tc <- test.input - ofcall := (<-rc).Ofcall - switch wantmsg := test.want.Ofcall.(type) { + ofcall := (<-rc).ofcall + switch wantmsg := test.want.ofcall.(type) { case *RAuth: gotmsg, ok := ofcall.(*RAuth) if !ok { @@ -243,7 +243,7 @@ func TestSFlush(t *testing.T) { go sFlush(ctx, s, tc) for _, test := range tests { tc <- test.input - if gotmsg, ok := (<-rc).Ofcall.(*RFlush); !ok { + if gotmsg, ok := (<-rc).ofcall.(*RFlush); !ok { t.Errorf("unexpected message: %v", gotmsg) } if _, ok := <-test.input.Oldreq.done; ok { diff --git a/server_test.go b/server_test.go @@ -29,26 +29,26 @@ func TestSAttach(t *testing.T) { input lib9p.Msg auth bool authOK bool - want *lib9p.Req + want lib9p.Msg }{ {&lib9p.TAttach{Fid: 0, Afid: lib9p.NOFID, Uname: "kenji", Aname: ""}, false, false, - &lib9p.Req{Ofcall: &lib9p.RError{}}}, // duplicate fid + &lib9p.RError{}}, // duplicate fid {&lib9p.TAttach{Fid: 1, Afid: lib9p.NOFID, Uname: "kenji", Aname: ""}, false, true, - &lib9p.Req{Ofcall: &lib9p.RAttach{}}}, // ok + &lib9p.RAttach{}}, // ok {&lib9p.TAttach{Fid: 2, Afid: lib9p.NOFID, Uname: "kenji", Aname: ""}, true, false, - &lib9p.Req{Ofcall: &lib9p.RError{}}}, // afid is not set + &lib9p.RError{}}, // afid is not set {&lib9p.TAttach{Fid: 2, Afid: 0, Uname: "kenji", Aname: ""}, true, false, - &lib9p.Req{Ofcall: &lib9p.RError{}}}, // not authOK + &lib9p.RError{}}, // not authOK {&lib9p.TAttach{Fid: 2, Afid: 0, Uname: "unko", Aname: ""}, true, true, - &lib9p.Req{Ofcall: &lib9p.RError{}}}, // wrong user + &lib9p.RError{}}, // wrong user {&lib9p.TAttach{Fid: 2, Afid: 0, Uname: "kenji", Aname: ""}, true, true, - &lib9p.Req{Ofcall: &lib9p.RAttach{}}}, // ok + &lib9p.RAttach{}}, // ok } tc := make(chan *lib9p.Req) rc := make(chan *lib9p.Req) @@ -71,8 +71,8 @@ func TestSAttach(t *testing.T) { req := new(lib9p.Req) req.SetIfcall(test.input) tc <- req - ofcall := (<-rc).Ofcall - switch wantmsg := test.want.Ofcall.(type) { + ofcall := (<-rc).Ofcall() + switch wantmsg := test.want.(type) { case *lib9p.RAttach: _, ok := ofcall.(*lib9p.RAttach) if !ok { @@ -133,7 +133,7 @@ func TestSWalk(t *testing.T) { req := new(lib9p.Req) req.SetIfcall(test.input) tc <- req - ofcall := (<-rc).Ofcall + ofcall := (<-rc).Ofcall() if test.wantErr == nil { gotMsg, ok := ofcall.(*lib9p.RWalk) if !ok { @@ -206,7 +206,7 @@ func TestSOpen(t *testing.T) { req := new(lib9p.Req) req.SetIfcall(test.input) tc <- req - ofcall := (<-rc).Ofcall + ofcall := (<-rc).Ofcall() switch test.wantMsg.(type) { case *lib9p.ROpen: if _, ok := ofcall.(*lib9p.ROpen); !ok {