lib9p

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

commit 702c8878d9bc6959e312163086c02052547819f5
parent b292ad05b96626b2ae1bc70e0e926d2c93ccc9a5
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sun, 31 Dec 2023 15:58:30 +0900

update cmd and
 tests

Diffstat:
Mclient/client_test.go | 4++--
Mclient/file_test.go | 4++--
Mcmd/diskfs/main.go | 20+++++++++-----------
Mcmd/iofs/main.go | 23++++++++++-------------
Mcmd/numfs/main.go | 20++++++++------------
Mcmd/semfs/main.go | 18++++++++----------
Mdiskfs/file_test.go | 4++--
Mdiskfs/stat_unix_test.go | 8++++----
8 files changed, 45 insertions(+), 56 deletions(-)

diff --git a/client/client_test.go b/client/client_test.go @@ -44,9 +44,9 @@ func TestTransaction(t *testing.T) { func TestClient2(t *testing.T) { cr, sw := io.Pipe() sr, cw := io.Pipe() - server := lib9p.NewServer(testfs.Fsys, mSize, sr, sw) + server := lib9p.NewServer(testfs.Fsys) //server.Chatty() - go server.Serve(context.Background()) + go server.Serve(context.Background(), sr, sw) fs, err := client.Mount(cr, cw, "kenji", "") if err != nil { t.Errorf("mount: %v", err) diff --git a/client/file_test.go b/client/file_test.go @@ -21,9 +21,9 @@ type FS struct { func mountTestFS(t *testing.T) *FS { cr, sw := io.Pipe() sr, cw := io.Pipe() - s := lib9p.NewServer(testfs.Fsys, 8*1024, sr, sw) + s := lib9p.NewServer(testfs.Fsys) ctx, cancel := context.WithCancel(context.Background()) - go s.Serve(ctx) + go s.Serve(ctx, sr, sw) fsys, err := client.Mount(cr, cw, "ken", "") if err != nil { t.Fatal(err) diff --git a/cmd/diskfs/main.go b/cmd/diskfs/main.go @@ -60,6 +60,10 @@ func main() { if err != nil { log.Fatalf("open file tree.") } + s := lib9p.NewServer(disk) + if *dFlag { + s.Chatty() + } L: for { conn, err := listener.Accept() @@ -73,21 +77,15 @@ L: } } wg.Add(1) - go handle(ctx, wg, conn, disk) + go func () { + defer conn.Close() + defer wg.Done() + s.Serve(ctx, conn, conn) + }() } wg.Wait() } -func handle(ctx context.Context, wg *sync.WaitGroup, conn net.Conn, disk *diskfs.FS) { - srv := lib9p.NewServer(disk, 8*1024, conn, conn) - if *dFlag { - srv.Chatty() - } - srv.Serve(ctx) - conn.Close() - wg.Done() -} - func runSignalHandler() context.Context { quit := make(chan os.Signal) signal.Notify(quit, os.Interrupt) diff --git a/cmd/iofs/main.go b/cmd/iofs/main.go @@ -31,24 +31,21 @@ func main() { if err != nil { log.Fatalf("listen tcp: %v", err) } - + dir := os.DirFS(flag.Arg(0)) + fsys := iofs.NewFS(dir) + s := lib9p.NewServer(fsys) + if *dFlag { + s.Chatty() + } for { conn, err := listener.Accept() if err != nil { log.Printf("accept connection: %v", err) continue } - dir := os.DirFS(flag.Arg(0)) - fsys := iofs.NewFS(dir) - go handle(conn, fsys) - } -} - -func handle(conn net.Conn, disk *iofs.FS) { - srv := lib9p.NewServer(disk, 8*1024, conn, conn) - if *dFlag { - srv.Chatty() + go func() { + defer conn.Close() + s.Serve(context.TODO(), conn, conn) + }() } - srv.Serve(context.Background()) - conn.Close() } diff --git a/cmd/numfs/main.go b/cmd/numfs/main.go @@ -198,23 +198,19 @@ func main() { if err != nil { log.Fatalf("listen tcp: %v", err) } - + s := lib9p.NewServer(fsys) + if *dFlag { + s.Chatty() + } for { conn, err := listener.Accept() if err != nil { log.Printf("accept connection: %v", err) continue } - - go handle(conn, fsys) - } -} - -func handle(conn net.Conn, fs *numFS) { - srv := lib9p.NewServer(fs, 8*1024, conn, conn) - if *dFlag { - srv.Chatty() + go func() { + defer conn.Close() + s.Serve(context.TODO(), conn, conn) + }() } - srv.Serve(context.Background()) - conn.Close() } diff --git a/cmd/semfs/main.go b/cmd/semfs/main.go @@ -24,21 +24,19 @@ func main() { log.Fatalf("listen tcp: %v", err) } fsys := &semFS{semfiles: make(map[int]*semFile)} + s := lib9p.NewServer(fsys) + if *dFlag { + s.Chatty() + } for { conn, err := listener.Accept() if err != nil { log.Printf("accept connection: %v", err) continue } - go handle(conn, fsys) - } -} - -func handle(conn net.Conn, fsys *semFS) { - srv := lib9p.NewServer(fsys, 8*1024, conn, conn) - if *dFlag { - srv.Chatty() + go func() { + defer conn.Close() + s.Serve(context.TODO(), conn, conn) + }() } - srv.Serve(context.Background()) - conn.Close() } diff --git a/diskfs/file_test.go b/diskfs/file_test.go @@ -23,8 +23,8 @@ func BenchmarkRead(b *testing.B) { if err != nil { b.Fatalf("open dir: %v", err) } - s := lib9p.NewServer(disk, 8*1024, sr, sw) - go s.Serve(ctx) + s := lib9p.NewServer(disk) + go s.Serve(ctx, sr, sw) c := client.NewClient(8*1024, "kenji", cr, cw) defer c.Stop() _, err = c.Attach(ctx, ^uint16(0), 0, lib9p.NOFID, "kenji", "") diff --git a/diskfs/stat_unix_test.go b/diskfs/stat_unix_test.go @@ -26,8 +26,8 @@ func BenchmarkGID(b *testing.B) { if err != nil { b.Fatalf("open dir: %v", err) } - s := lib9p.NewServer(disk, 8*1024, sr, sw) - go s.Serve(ctx) + s := lib9p.NewServer(disk) + go s.Serve(ctx, sr, sw) c := client.NewClient(8*1024, "kenji", cr, cw) defer c.Stop() _, err = c.Attach(ctx, ^uint16(0), 0, lib9p.NOFID, "kenji", "") @@ -55,8 +55,8 @@ func TestChgrp(t *testing.T) { if err != nil { t.Fatalf("open dir: %v", err) } - s := lib9p.NewServer(disk, 8*1024, sr, sw) - go s.Serve(ctx) + s := lib9p.NewServer(disk) + go s.Serve(ctx, sr, sw) c := client.NewClient(8*1024, "kenji", cr, cw) defer c.Stop() _, err = c.Attach(ctx, ^uint16(0), 0, lib9p.NOFID, "kenji", "")