Blame


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