lib9p

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

commit ed8ed546fc59c825a7d435d0e9841664bdf32aa2
parent 4188c62878f3bc0a90430cd3aa6bbdf1788f0323
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 25 Dec 2023 12:51:44 +0900

delete rauth

Diffstat:
Mserver.go | 46+++++++++++-----------------------------------
1 file changed, 11 insertions(+), 35 deletions(-)

diff --git a/server.go b/server.go @@ -227,20 +227,17 @@ func sVersion(ctx context.Context, s *Server, c <-chan *Req) { Msize: msize, Version: version, } - r.Srv.setMSize(r.Ofcall.(*RVersion).Msize) - r.Srv.respChan <- r + s.setMSize(r.Ofcall.(*RVersion).Msize) + s.respChan <- r } } } // sAuth serves Tauth message. func sAuth(ctx context.Context, s *Server, c <-chan *Req) { - rc := make(chan *Req) - defer close(rc) - go rAuth(ctx, rc) var authc chan<- *Req if s.Auth != nil { - authc = s.Auth(ctx, rc) + authc = s.Auth(ctx, s.respChan) defer close(authc) } for { @@ -251,41 +248,20 @@ func sAuth(ctx context.Context, s *Server, c <-chan *Req) { if !ok { return } + if authc == nil { + setError(r, fmt.Errorf("authentication not required")) + s.respChan <- r + continue + } ifcall := r.Ifcall.(*TAuth) var err error r.Afid, err = s.fPool.add(ifcall.Afid) if err != nil { - r.err = ErrDupFid - rc <- r + setError(r, ErrDupFid) + s.respChan <- r continue } - if authc != nil { - authc <- r - } else { - r.err = fmt.Errorf("authentication not required") - rc <- r - continue - } - } - } -} - -// rAuth checks if err is nil, and if not, it deletes the -// allocated fid from fPool. -func rAuth(ctx context.Context, c <-chan *Req) { - for { - select { - case <-ctx.Done(): - return - case r, ok := <-c: - if !ok { - return - } - if r.err != nil { - r.Srv.fPool.delete(r.Ifcall.(*TAuth).Afid) - setError(r, r.err) - } - r.Srv.respChan <- r + authc <- r // TODO: I think Req.listenErr should be exported. } } }