commit 336e8e1f3f6e5e4110474f882860c714625711cf
parent 95d560fcbdd3772213b0fdcd84b5a242b528e4c6
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 25 Dec 2023 08:25:30 +0900
change done check to use ok
Diffstat:
| M | server.go | | | 179 | ++++++++++++++++++++++++++----------------------------------------------------- |
1 file changed, 58 insertions(+), 121 deletions(-)
diff --git a/server.go b/server.go
@@ -205,11 +205,9 @@ func sVersion(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TVersion)
version := ifcall.Version
@@ -238,11 +236,9 @@ func rVersion(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
panic(fmt.Errorf("rVersion err: %w", r.err))
@@ -267,11 +263,9 @@ func sAuth(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TAuth)
var err error
@@ -299,11 +293,9 @@ func rAuth(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
r.Srv.fPool.delete(r.Ifcall.(*TAuth).Afid)
@@ -322,11 +314,9 @@ func sAttach(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TAttach)
fid, err := s.fPool.add(ifcall.Fid)
@@ -387,11 +377,9 @@ func rAttach(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
r.Srv.fPool.delete(r.Ifcall.(*TAttach).Fid)
@@ -410,11 +398,9 @@ func sFlush(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
rc <- r
}
@@ -426,11 +412,9 @@ func rFlush(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
panic(fmt.Errorf("err in flush: %v", r.err))
@@ -452,11 +436,9 @@ func sWalk(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TWalk)
oldFid, ok := s.fPool.lookup(ifcall.Fid)
@@ -522,11 +504,9 @@ func rWalk(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TWalk)
if r.Ofcall == nil {
@@ -561,14 +541,11 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TOpen)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -667,11 +644,9 @@ func rOpen(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -703,14 +678,11 @@ func sCreate(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TCreate)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -776,11 +748,9 @@ func rCreate(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -800,14 +770,11 @@ func sRead(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TRead)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -905,11 +872,9 @@ func rRead(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -928,14 +893,11 @@ func sWrite(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TWrite)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -996,11 +958,9 @@ func rWrite(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -1018,11 +978,9 @@ func sClunk(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TClunk)
fid, ok := s.fPool.lookup(ifcall.Fid)
@@ -1050,11 +1008,9 @@ func rClunk(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
log.Printf("clunk: %v", r.err)
@@ -1073,14 +1029,11 @@ func sRemove(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TRemove)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -1125,11 +1078,9 @@ func rRemove(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -1147,14 +1098,11 @@ func sStat(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TStat)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -1180,11 +1128,9 @@ func rStat(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -1202,14 +1148,11 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
ifcall := r.Ifcall.(*TWStat)
- var ok bool
r.Fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
@@ -1351,11 +1294,9 @@ func rWStat(ctx context.Context, c <-chan *Req) {
select {
case <-ctx.Done():
return
- case r := <-c:
- select {
- case <-ctx.Done():
+ case r, ok := <-c:
+ if !ok {
return
- default:
}
if r.err != nil {
setError(r, r.err)
@@ -1418,11 +1359,11 @@ func (s *Server) Serve(ctx context.Context) {
L:
for {
select {
- case r := <-s.listenChan:
- select {
- case <-ctx.Done():
+ case <-ctx.Done():
+ break L
+ case r, ok := <-s.listenChan:
+ if !ok {
break L
- default:
}
if r.listenErr != nil {
log.Printf("listen: %v", r.listenErr)
@@ -1468,8 +1409,6 @@ L:
wstatChan <- r
}
}()
- case <-ctx.Done():
- break L
}
}
}
@@ -1479,11 +1418,9 @@ func respond(ctx context.Context, s *Server) {
select {
case <-ctx.Done():
return
- case r := <-s.respChan:
- select {
- case <-ctx.Done():
+ case r, ok := <-s.respChan:
+ if !ok {
return
- default: // respChan should be closed after ctx is canceled.
}
r.Ofcall.SetTag(r.Tag)
// free tag.