lib9p

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

commit 6d0fd8871411f1345b1cf091b6132f989596edc5
parent 3529506575eab96178d36dd4cd98d9b4bdb17bcd
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 30 Dec 2023 08:42:20 +0900

add document

Diffstat:
Mauth.go | 2+-
Mcmd/diskfs/main.go | 9++++++---
Mdoc.go | 37+++++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/auth.go b/auth.go @@ -8,7 +8,7 @@ import ( // An AuthFile is a file allocated by Auth function of Server struct. // If authentication is desired, Auth member of Server struct must be set -// and it should set an AuthFile ready to Read/Write via R/W struct. +// and it should set an AuthFile ready to Read/Write via R/W member. type AuthFile struct { Qid Qid Uname string diff --git a/cmd/diskfs/main.go b/cmd/diskfs/main.go @@ -24,6 +24,7 @@ import ( var dFlag = flag.Bool("D", false, "Prints chatty message to the stderr.") var aFlag = flag.String("a", "127.0.0.1", "Address the server listens to.") var pFlag = flag.Int("p", 5640, "Port number the server listens to.") +var PFlag = flag.Int("P", 0, "Enables pprof over http on this port.") var gFlag = flag.Bool("g", false, "Prints goroutin count once per second.") func main() { @@ -40,9 +41,11 @@ func main() { } }() } - go func() { - log.Println(http.ListenAndServe(fmt.Sprintf("%s:8000", *aFlag), nil)) - }() + if *PFlag != 0 { + go func() { + log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *aFlag, *PFlag), nil)) + }() + } listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *aFlag, *pFlag)) if err != nil { log.Fatalf("listen tcp: %v", err) diff --git a/doc.go b/doc.go @@ -1,2 +1,39 @@ // Package lib9p is a 9P2000 library to implement 9P servers. +// For detailed information on 9P protocol, consult the protocol's documentation. +// +// To use this package, implement the [FS] interface, and +// create a [Server] struct by calling [NewServer] with the [FS], and +// then call [*Server.Serve]. +// The server listens to r specified by the argument of [NewServer] and +// writes responses to w. +// It does not assume network connection, and can be used with any +// [io.Reader]/[io.Writer]. +// If the server is to serve via a tcp connection, write something like the +// following code: +// +// l, err := net.Listen("tcp", "localhost:5640") +// if err != nil { +// log.Fatal(err) +// } +// for { +// conn, err := l.Accept() +// if err != nil { +// log.Print(err) +// } +// s := lib9p.NewServer(fsys, 8*1024, conn, conn) +// go s.Serve(context.Background()) +// } +// +// OpenFile method of [FS] interface is similar to that of [os.OpenFile], +// but it takes as argument OpenMode instead of integer flag. +// And it does not create file even if the specified file does not exists. +// The returned value is [File], not [fs.File]. +// +// A [File] is the representation of a file of the exported file system. +// It is almost identical to [fs.File], but the Stat method returns the +// [*FileInfo] struct instead of [fs.FileInfo] interface. +// The difference of [*FileInfo] and [fs.FileInfo] is that the Sys method +// of [*FileInfo] returns the underlying [*Stat] struct as a value of any, +// while I can't asume anything on Stat of [fs.FileInfo]. +// This ensures the type safety. package lib9p