commit 72c9a8f3eefc0ab1eb1509e6acd24a948345cc90
parent 07db670dcac0fc8439d0580daf4e9259b2f3ed62
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 30 Dec 2023 12:35:26 +0900
add comment on file lock
Diffstat:
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/cmd/diskfs/main.go b/cmd/diskfs/main.go
@@ -56,6 +56,10 @@ func main() {
listener.Close()
}()
wg := new(sync.WaitGroup)
+ disk, err := diskfs.Open(flag.Arg(0))
+ if err != nil {
+ log.Fatalf("open file tree.")
+ }
L:
for {
conn, err := listener.Accept()
@@ -68,10 +72,6 @@ L:
continue L
}
}
- disk, err := diskfs.Open(flag.Arg(0))
- if err != nil {
- log.Fatalf("open file tree.")
- }
wg.Add(1)
go handle(ctx, wg, conn, disk)
}
diff --git a/server.go b/server.go
@@ -788,7 +788,7 @@ func sRead(ctx context.Context, s *Server, c <-chan *request) {
}
}
-// TODO: I think the file should be locked while reading.
+// TODO: I think the file should be locked while writing.
func sWrite(ctx context.Context, s *Server, c <-chan *request) {
for {
select {
@@ -1146,6 +1146,11 @@ func sWStat(ctx context.Context, s *Server, c <-chan *request) {
}
// Serve serves 9P conversation.
+// TODO: If the user of the library make a Server for each
+// connection to the same filesystem, those Servers can access
+// the same file concurrentry.
+// So some additional struct to represent each connection is needed.
+// And Serve method should be attached to that struct.
func (s *Server) Serve(ctx context.Context) {
rp := newReqPool()
s.runListener(ctx, rp)