lib9p

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

commit 1f3935ea80fa09e85f9a8d5deadbd8c94d93e67b
parent 418ddacedb1be0d07bb58845af2c5594a0dcaea0
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue,  9 Jan 2024 19:06:18 +0900

replace errc with done channel

Diffstat:
Mserver.go | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/server.go b/server.go @@ -838,8 +838,9 @@ func sWrite(ctx context.Context, c *conn, rc <-chan *request) { } var ( ofcall *RWrite - errc chan error + done chan struct{} omode OpenMode + err error ) ifcall := r.ifcall.(*TWrite) r.fid, ok = c.fPool.lookup(ifcall.Fid) @@ -856,31 +857,30 @@ func sWrite(ctx context.Context, c *conn, rc <-chan *request) { goto resp } ofcall = new(RWrite) - errc = make(chan error) + done = make(chan struct{}) go func() { - defer close(errc) + defer close(done) + var n int switch file := r.fid.file.(type) { case io.WriterAt: - n, err := file.WriteAt(ifcall.Data, int64(ifcall.Offset)) + n, err = file.WriteAt(ifcall.Data, int64(ifcall.Offset)) if err != nil { - errc <- fmt.Errorf("write: %v", err) return } ofcall.Count = uint32(n) case io.Writer: - n, err := file.Write(ifcall.Data) + n, err = file.Write(ifcall.Data) if err != nil { - errc <- fmt.Errorf("write: %v", err) return } ofcall.Count = uint32(n) default: - errc <- ErrOperation + err = ErrOperation return } }() select { - case err := <-errc: + case <-done: if err != nil { r.err = err goto resp