Blob


1 package p9pnew
3 import (
4 "net"
6 "golang.org/x/net/context"
7 )
9 // Session provides the central abstraction for a 9p connection. Clients
10 // implement sessions and servers serve sessions. Sessions can be proxied by
11 // serving up a client session.
12 //
13 // The interface is also wired up with full context support to manage timeouts
14 // and resource clean up.
15 //
16 // Session represents the operations covered in section 5 of the plan 9 manual
17 // (http://man.cat-v.org/plan_9/5/). Requests are managed internally, so the
18 // Flush method is handled by the internal implementation. Consider preceeding
19 // these all with context to control request timeout.
20 type Session interface {
21 Auth(ctx context.Context, afid Fid, uname, aname string) (Qid, error)
22 Attach(ctx context.Context, fid, afid Fid, uname, aname string) (Qid, error)
23 Clunk(ctx context.Context, fid Fid) error
24 Remove(ctx context.Context, fid Fid) error
25 Walk(ctx context.Context, fid Fid, newfid Fid, names ...string) ([]Qid, error)
26 Read(ctx context.Context, fid Fid, p []byte, offset int64) (n int, err error)
27 Write(ctx context.Context, fid Fid, p []byte, offset int64) (n int, err error)
28 Open(ctx context.Context, fid Fid, mode uint8) (Qid, uint32, error)
29 Create(ctx context.Context, parent Fid, name string, perm uint32, mode uint32) (Qid, uint32, error)
30 Stat(context.Context, Fid) (Dir, error)
31 WStat(context.Context, Fid, Dir) error
33 // Version returns the supported version and msize of the session. This
34 // can be affected by negotiating or the level of support provided by the
35 // session implementation.
36 Version() (msize uint32, version string)
37 }
39 func Dial(ctx context.Context, addr string) (Session, error) {
40 c, err := net.Dial("tcp", addr)
41 if err != nil {
42 return nil, err
43 }
45 // BUG(stevvooe): Session doesn't actually close connection. Dial might
46 // not be the right interface.
48 return NewSession(ctx, c)
49 }