lib9p

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

commit a32f1c02bbb6f3c7b80d812569e8e165a9a43f88
parent 783ac9457889da947eb86519ab6fcd12c4d7be2f
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 29 Dec 2023 09:17:13 +0900

unexport ReqPool

Diffstat:
Mexport_test.go | 1+
Mreq.go | 22+++++++++++-----------
Mserver.go | 8++++----
3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/export_test.go b/export_test.go @@ -64,6 +64,7 @@ func (r *Req) Ofcall() Msg { return r.ofcall } func (r *Req) SetOfcall(m Msg) { r.ofcall = m } func (r *Req) Afid() *Fid { return r.afid } +type ReqPool = reqPool func (rp *ReqPool) Add(tag uint16) (*Req, error) { return rp.add(tag) } func (fid *Fid) SetPath(path string) { fid.path = path } diff --git a/req.go b/req.go @@ -16,7 +16,7 @@ type request struct { // Oldreq is set with Tflush message. oldreq *request // Pool is the pool this request belongs to. - pool *ReqPool + pool *reqPool // Done is used by time consuming goroutines to check whether the request // is flushed. done chan struct{} @@ -38,27 +38,27 @@ func (r *request) flush() { r.pool.delete(r.tag) } -// ReqPool is the pool of Reqs the server is dealing with. -type ReqPool struct { +// reqPool is the pool of Reqs the server is dealing with. +type reqPool struct { m map[uint16]*request lock *sync.Mutex } -// newReqPool allocats a ReqPool. -func newReqPool() *ReqPool { - return &ReqPool{ +// newReqPool allocats a reqPool. +func newReqPool() *reqPool { + return &reqPool{ m: make(map[uint16]*request), lock: new(sync.Mutex), } } -// Add allocates a request with the specified tag in ReqPool rp. +// Add allocates a request with the specified tag in reqPool rp. // It returns (nil, ErrDupTag) if there is already a request with the specified tag. -func (rp *ReqPool) add(tag uint16) (*request, error) { +func (rp *reqPool) add(tag uint16) (*request, error) { return reqPoolAdd(rp, tag) } -var reqPoolAdd = func(rp *ReqPool, tag uint16) (*request, error) { +var reqPoolAdd = func(rp *reqPool, tag uint16) (*request, error) { rp.lock.Lock() defer rp.lock.Unlock() if _, ok := rp.m[tag]; ok { @@ -75,7 +75,7 @@ var reqPoolAdd = func(rp *ReqPool, tag uint16) (*request, error) { // lookup looks for the request in the pool with tag. // If found, it returns the found request and true, otherwise // it returns nil and false. -func (rp *ReqPool) lookup(tag uint16) (*request, bool) { +func (rp *reqPool) lookup(tag uint16) (*request, bool) { rp.lock.Lock() defer rp.lock.Unlock() r, ok := rp.m[tag] @@ -83,7 +83,7 @@ func (rp *ReqPool) lookup(tag uint16) (*request, bool) { } // delete delets the request with tag from the pool. -func (rp *ReqPool) delete(tag uint16) { +func (rp *reqPool) delete(tag uint16) { rp.lock.Lock() defer rp.lock.Unlock() delete(rp.m, tag) diff --git a/server.go b/server.go @@ -46,7 +46,7 @@ type Server struct { fPool *FidPool // Pending Requests the server is dealing with. - rPool *ReqPool + rPool *reqPool // The channel from which incoming requests are delivered by the // listener goroutine. @@ -107,7 +107,7 @@ func (s *Server) setMSize(mSize uint32) { // runListener runs the listener goroutine. // Listener goroutine reads 9P messages from s.r by calling getReq // and allocats request for each of them, and sends it to the server's listenChan. -func (s *Server) runListener(ctx context.Context, rp *ReqPool) { +func (s *Server) runListener(ctx context.Context, rp *reqPool) { rc := make(chan *request) s.listenChan = rc go func() { @@ -125,7 +125,7 @@ func (s *Server) runListener(ctx context.Context, rp *ReqPool) { // 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) runResponder(ctx context.Context, rp *ReqPool) { +func (s *Server) runResponder(ctx context.Context, rp *reqPool) { rc := make(chan *request) s.respChan = rc go func() { @@ -159,7 +159,7 @@ func (s *Server) runResponder(ctx context.Context, rp *ReqPool) { // Any error it encountered is embedded into the request struct. // This function is called only by the server's listener goroutine, // and does not need to lock s.r. -func getReq(r io.Reader, rp *ReqPool, chatty bool) *request { +func getReq(r io.Reader, rp *reqPool, chatty bool) *request { ifcall, err := RecvMsg(r) if err != nil { if err == io.EOF {