lib9p

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

commit 09ff73e4d321b41f9cb218f61947e94bc4250a7e
parent 6924559fb2165ec052ec4c40a9d1f7dc76294ee4
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 27 Oct 2023 08:12:23 +0900

change function names

Diffstat:
Mparse.go | 12++++++------
Mserver.go | 24++++++------------------
2 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/parse.go b/parse.go @@ -8,7 +8,7 @@ import ( // Read9PMsg reads a 9P message from r and saves it in a byte slice. // It returns the byte slice read and error if any. -func read9PMsg(r io.Reader) ([]byte, error) { +func readMsg(r io.Reader) ([]byte, error) { buf := make([]byte, 4) read, err := r.Read(buf) if err != nil { @@ -96,17 +96,17 @@ func unmarshal(buf []byte) (Msg, error) { } } -// send send msg to w -func send(msg Msg, w io.Writer) error { +// SendMsg send a 9P message to w +func SendMsg(msg Msg, w io.Writer) error { if _, err := w.Write(msg.marshal()); err != nil { return fmt.Errorf("write: %v", err) } return nil } -// recv recievs 9P messages from r. -func recv(r io.Reader) (Msg, error) { - b, err := read9PMsg(r) +// RecvMsg recievs a 9P message from r. +func RecvMsg(r io.Reader) (Msg, error) { + b, err := readMsg(r) if err == io.EOF { return nil, err } else if err != nil { diff --git a/server.go b/server.go @@ -150,39 +150,27 @@ func (s *Server) runSpeaker(w io.Writer) (chan<- *Req, <-chan error) { // This function is called only by the server's listener goroutine, // and does not need to lock r. func getReq(r io.Reader, s *Server) (*Req, error) { - buf, err := read9PMsg(r) + ifcall, err := RecvMsg(r) if err != nil { if err == io.EOF { return nil, err } - return nil, fmt.Errorf("recv: %v", err) + return nil, fmt.Errorf("readMsg: %v", err) } - req, err := s.rPool.add(bufMsg(buf).GetTag()) + req, err := s.rPool.add(ifcall.GetTag()) if err != nil { // duplicate tag: cons up a fake Req req := new(Req) req.srv = s - req.ifcall, err = unmarshal(buf) - if err != nil { - log.Printf("unmarshal: %v", err) - req.ifcall = bufMsg(buf) - } + req.ifcall = ifcall if s.chatty9P { fmt.Fprintf(os.Stderr, "<-- %v\n", req.ifcall) } return req, ErrDupTag } req.srv = s - req.tag = bufMsg(buf).GetTag() - req.ifcall, err = unmarshal(buf) - if err != nil { - log.Printf("unmarshal: %v", err) - if s.chatty9P { - fmt.Fprintf(os.Stderr, "<-- %v\n", bufMsg(buf)) - } - req.ifcall = bufMsg(buf) - return req, err - } + req.tag = ifcall.GetTag() + req.ifcall = ifcall if ifcall, ok := req.ifcall.(*TFlush); ok { req.oldReq, _ = req.srv.rPool.lookup(ifcall.Oldtag) }