commit 16f75c0f938ca6770627985b54bfb64e5245bbaf
parent bf3141ec2d8a53f3a4e7988a10062e5184b442ad
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 22 Oct 2023 07:16:10 +0900
add comments
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/client.go b/client.go
@@ -55,6 +55,11 @@ func (c *Client) setMSize(mSize uint32) {
c.msize = mSize
}
+// RunListener runs listener goroutine.
+// Listener reads byte array of 9P messages from r and make each of them into
+// corresponding struct that implements Msg, and sends it to the returned channel.
+// Listener goroutine returns when ctx is canceled.
+// Listener goroutine reports errors to the client's errc channel.
func (c *Client) runListener(ctx context.Context, r io.Reader) <-chan Msg {
// TODO: terminate with ctx.Done()
rmsgc := make(chan Msg, 3)
@@ -83,6 +88,11 @@ func (c *Client) runListener(ctx context.Context, r io.Reader) <-chan Msg {
return rmsgc
}
+// RunSpeaker runs speaker goroutine.
+// Speaker goroutine recieves 9P Msgs from the returned channel, marshal them
+// into byte arrays and sends them to w.
+// It reports any errors to the clients errc channel.
+// It returnes when ctx is canceled.
func (c *Client) runSpeaker(ctx context.Context, w io.Writer) chan<- Msg {
tmsgc := make(chan Msg, 3)
go func() {
@@ -100,6 +110,15 @@ func (c *Client) runSpeaker(ctx context.Context, w io.Writer) chan<- Msg {
return tmsgc
}
+// RunMultiplexer runs multiplexer goroutine.
+// Multiplexer goroutines, one for recieving Rmsg and another for sending Tmsg.
+// The goroutine for Tmsg recieves *clientReq from the returned channel,
+// and send the 9P Msg to the speaker goroutine via tmsgc.
+// The goroutine for Rmsg recieves *clientReq from the Tmsg goroutine and waits for
+// the reply to the corresponding message from the listener goroutine via rmsgc.
+// After recieving the reply, it sets the *clientReq.rmsg and sends it t the
+// *clientReq.rxc.
+// It reports any errors to the client's errc channel.
func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- Msg, rmsgc <-chan Msg) chan<- *clientReq {
txc := make(chan *clientReq)
reqc := make(chan *clientReq)
@@ -153,6 +172,8 @@ func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- Msg, rmsgc <-c
return txc
}
+// Transact send 9P Msg of req to the multiplexer goroutines and recieves
+// the reply.
func (c *Client) transact(ctx context.Context, req *clientReq) (Msg, error) {
select {
case <-ctx.Done():