lib9p

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

commit dadf3adcd68dc6d0d0d0a7977219bbc8acb582c7
parent a9b45b66283b83ecb64577a8fc1be549375c12e8
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 29 Dec 2023 08:43:51 +0900

rename

Diffstat:
Mexport_test.go | 4++--
Mserver.go | 23+++++++++++------------
Mserver2_test.go | 6+++---
3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/export_test.go b/export_test.go @@ -48,8 +48,8 @@ func (s *Server) FPool() *FidPool { return s.fPool } func (s *Server) RunListener(ctx context.Context, rp *ReqPool) { s.runListener(ctx, rp) } -func (s *Server) RunSpeaker(ctx context.Context, rp *ReqPool) { - s.runSpeaker(ctx, rp) +func (s *Server) RunResponder(ctx context.Context, rp *ReqPool) { + s.runResponder(ctx, rp) } func (s *Server) SetFS(fs FS) { s.fs = fs } func (s *Server) SetRespChan(rc chan *Req) { s.respChan = rc } diff --git a/server.go b/server.go @@ -55,15 +55,14 @@ type Server struct { // It should be accessed only by the listener goroutine. r io.Reader - // The channel to which outgoing replies are sent to the speaker + // The channel to which outgoing replies are sent to the responder // goroutine. - speakChan chan<- *Req - // w is the io.Writer which the speaker goroutine writes to. - // It should be accessed only by the speaker goroutine. - w io.Writer - respChan chan *Req + // w is the io.Writer which the responder goroutine writes to. + // It should be accessed only by the responder goroutine. + w io.Writer + // Auth function is passed an auth request when a TAuth message arrives // If authentication is desired, Auth should // set Req.Afid.File to an *AuthFile and Req.Ofcall.Qid, and prepare to @@ -73,7 +72,7 @@ type Server struct { Auth func(ctx context.Context, r *Req) } -// NewServer creates a Server and runs listener and speaker goroutines. +// NewServer creates a Server and runs listener and responder goroutines. // It reads incoming messages from r and writes responses to w. func NewServer(fsys FS, mSize uint32, r io.Reader, w io.Writer) *Server { s := &Server{ @@ -123,10 +122,10 @@ func (s *Server) runListener(ctx context.Context, rp *ReqPool) { }() } -// runSpeaker runs the speaker goroutine. -// Speaker goroutine wait for reply Requests from the returned channel, +// runResponder runs the responder goroutine. +// Responder goroutine wait for reply Requests from the returned channel, // and marshalls each of them into 9P messages and writes it to s.w. -func (s *Server) runSpeaker(ctx context.Context, rp *ReqPool) { +func (s *Server) runResponder(ctx context.Context, rp *ReqPool) { rc := make(chan *Req) s.respChan = rc go func() { @@ -142,7 +141,7 @@ func (s *Server) runSpeaker(ctx context.Context, rp *ReqPool) { _, err := s.w.Write(r.Ofcall.marshal()) if err != nil { // TODO: handle error. - log.Printf("speak: %v", err) + log.Printf("respond: %v", err) continue } if s.chatty9P { @@ -1150,7 +1149,7 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) { func (s *Server) Serve(ctx context.Context) { rp := newReqPool() s.runListener(ctx, rp) - s.runSpeaker(ctx, rp) + s.runResponder(ctx, rp) var ( versionChan = make(chan *Req) authChan = make(chan *Req) diff --git a/server2_test.go b/server2_test.go @@ -56,7 +56,7 @@ func TestRunListener(t *testing.T) { // TestRunSpeaker tests if the speaker goroutine receives 9P messages // and send them through the server's speakChan channel. -func TestRunSpeaker(t *testing.T) { +func TestRunResponder(t *testing.T) { rFile, err := os.Open("testdata/test_Rmsg.dat") if err != nil { t.Fatalf("open file: %v", err) @@ -67,7 +67,7 @@ func TestRunSpeaker(t *testing.T) { rp := newReqPool() ctx, cancel := context.WithCancel(context.Background()) defer cancel() - s.runSpeaker(ctx, rp) + s.runResponder(ctx, rp) for { want, err := readMsg(rFile) if err == io.EOF { @@ -89,7 +89,7 @@ func TestRunSpeaker(t *testing.T) { t.Fatalf("readfull: %v", err) } if !bytes.Equal(want, got) { - t.Errorf("speaker modified message:\n\twant: %v\n\tgot: %v", + t.Errorf("responder modified message:\n\twant: %v\n\tgot: %v", want, got) } }