commit 9195bcd6cff0707bdabf5dba81787d8429f6f91b
parent 99140d0231703ffba9f8e08b33029f2fa6922bcb
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sun, 21 Jan 2024 09:50:05 +0900
update comments
Diffstat:
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/client/client.go b/client/client.go
@@ -92,6 +92,11 @@ func (c *Client) runErrorReporter(ctx context.Context) {
 				}
 				switch {
 				case errors.Is(err, io.EOF):
+					return
+				// case receive error:
+				// case send error:
+				// I want to flush all blocking request calls by
+				// returning the error.
 				default:
 				}
 				log.Println("client err:", err)
@@ -119,6 +124,11 @@ func (c *Client) runMultiplexer(ctx context.Context, r io.Reader, w io.Writer) c
 	go func() {
 		defer c.wg.Done()
 		for {
+			select {
+			case <-ctx.Done():
+				return
+			default:
+			}
 			msg, err := lib9p.RecvMsg(r)
 			if err != nil {
 				if err == io.EOF {
@@ -131,7 +141,7 @@ func (c *Client) runMultiplexer(ctx context.Context, r io.Reader, w io.Writer) c
 			rq, ok := rPool.lookup(msg.GetTag())
 			if !ok {
 				c.errc <- fmt.Errorf("mux: unknown tag for msg: %v", msg)
-				continue
+				continue // TODO: how to recover?
 			}
 			rPool.delete(msg.GetTag())
 			if tflush, ok := rq.tmsg.(*lib9p.TFlush); ok {
@@ -175,7 +185,7 @@ func (c *Client) runMultiplexer(ctx context.Context, r io.Reader, w io.Writer) c
 	return txc
 }
 
-// Transact send 9P lib9p.Msg of r to the multiplexer goroutines and recieves
+// Transact sends 9P tmsg to the multiplexer and recieves
 // the reply.
 func (c *Client) transact(tmsg lib9p.Msg) (lib9p.Msg, error) {
 	r := newReq(tmsg)