commit 61e6fe997f7da54050d3ff5c23d4748ec64434a1
parent 966c1a229a50c1edad22c68cdce34ab275098888
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 15 Sep 2023 12:06:33 +0900
goruntine
Diffstat:
3 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/req.go b/req.go
@@ -21,11 +21,11 @@ func allocReqPool() *ReqPool {
return rp
}
-// AllocReq allocates a Req with the specified tag in ReqPool rp.
-// It returns nil, error if there is already a Req with the specified tag.
+// AddReq allocates a Req with the specified tag in ReqPool rp.
+// It returns nil, ErrDupTag if there is already a Req with the specified tag.
func (rp *ReqPool) addReq(tag uint16) (*Req, error) {
if _, ok := rp.m[tag]; ok {
- return nil, fmt.Errorf("duplicate tag %d", tag)
+ return nil, ErrDupTag
}
req := new(Req)
req.pool = rp
diff --git a/server.go b/server.go
@@ -670,34 +670,36 @@ func (s *Server) Serve() {
respond(r, err)
continue
}
- switch r.ifcall.(type) {
- default:
- respond(r, fmt.Errorf("unknown message type: %d", r.ifcall.Type()))
- case *TVersion:
- sVersion(s, r)
- case *TAuth:
- sAuth(s, r)
- case *TAttach:
- sAttach(s, r)
- case *TWalk:
- sWalk(s, r)
- case *TOpen:
- sOpen(s, r)
- case *TCreate:
- sCreate(s, r)
- case *TRead:
- sRead(s, r)
- case *TWrite:
- sWrite(s, r)
- case *TClunk:
- sClunk(s, r)
- case *TRemove:
- sRemove(s, r)
- case *TStat:
- sStat(s, r)
- case *TWStat:
- sWStat(s, r)
- }
+ go func(s *Server, r *Req) {
+ switch r.ifcall.(type) {
+ default:
+ respond(r, fmt.Errorf("unknown message type: %d", r.ifcall.Type()))
+ case *TVersion:
+ sVersion(s, r)
+ case *TAuth:
+ sAuth(s, r)
+ case *TAttach:
+ sAttach(s, r)
+ case *TWalk:
+ sWalk(s, r)
+ case *TOpen:
+ sOpen(s, r)
+ case *TCreate:
+ sCreate(s, r)
+ case *TRead:
+ sRead(s, r)
+ case *TWrite:
+ sWrite(s, r)
+ case *TClunk:
+ sClunk(s, r)
+ case *TRemove:
+ sRemove(s, r)
+ case *TStat:
+ sStat(s, r)
+ case *TWStat:
+ sWStat(s, r)
+ }
+ }(s, r)
}
}
@@ -746,7 +748,6 @@ func respond(r *Req, err error) {
if chatty9P {
fmt.Fprintf(os.Stderr, "--> %s\n", r.ofcall)
}
- r.srv.Writer.Write(r.ofcall.marshal())
// free tag.
if r.pool == nil && err != ErrDupTag {
@@ -757,4 +758,5 @@ func respond(r *Req, err error) {
panic(fmt.Errorf("deleteReq: %v", err))
}
}
+ r.srv.Writer.Write(r.ofcall.marshal())
}
diff --git a/testdir/c b/testdir/c
@@ -0,0 +1 @@
+unko