lib9p

Go 9P library.
Log | Files | Refs

commit 74209f71af93744374f15b3dc41acdce54c587d5
parent d7e3943a281746600827d253f5533828cb69bcf7
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 25 Sep 2023 16:40:56 +0900

add flush, wip

Diffstat:
Mreq.go | 12++++++++++++
Mserver.go | 18+++++++++++++++---
2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/req.go b/req.go @@ -11,9 +11,14 @@ type Req struct { ofcall Msg fid *Fid afid *Fid + oldReq *Req pool *ReqPool } +func (r *Req) flush() { + +} + type ReqPool struct { m map[uint16]*Req lock *sync.Mutex @@ -42,6 +47,13 @@ func (rp *ReqPool) add(tag uint16) (*Req, error) { return req, nil } +func (rp *ReqPool) lookup(tag uint16) (*Req, bool) { + rp.lock.Lock() + defer rp.lock.Unlock() + r, ok := rp.m[tag] + return r, ok +} + func (rp *ReqPool) delete(tag uint16) { rp.lock.Lock() defer rp.lock.Unlock() diff --git a/server.go b/server.go @@ -115,7 +115,6 @@ func (s *Server) getReq() (*Req, error) { return r, nil } - // TODO: abort all outstanding I/O on the same connection. func sVersion(s *Server, r *Req) { ifcall := r.ifcall.(*TVersion) @@ -201,8 +200,21 @@ func rAttach(r *Req, err error) { } } -func sFlush(s *Server, r *Req) {} -func rFlush(r *Req, err error) {} +func sFlush(s *Server, r *Req) { + ifcall := r.ifcall.(*TFlush) + r.oldReq, _ = s.rPool.lookup(ifcall.OldTag()) + respond(r, nil) +} + +func rFlush(r *Req, err error) { + if err != nil { + panic("err in flush") + } + if r.oldReq != nil { + r.oldReq.flush() + } + r.ofcall = &RFlush{} +} func sWalk(s *Server, r *Req) { ifcall := r.ifcall.(*TWalk)