func newConn(srv *Server, rwc io.ReadWriteCloser) *conn { var msize int64 = styxproto.DefaultMaxSize if srv.MaxSize > 0 { if srv.MaxSize > styxproto.MinBufSize { msize = srv.MaxSize } else { msize = styxproto.MinBufSize } } var enc *styxproto.Encoder var dec *styxproto.Decoder if srv.TraceLog != nil { enc = tracing.Encoder(rwc, func(m styxproto.Msg) { srv.TraceLog.Printf("← %03d %s", m.Tag(), m) }) dec = tracing.Decoder(rwc, func(m styxproto.Msg) { srv.TraceLog.Printf("→ %03d %s", m.Tag(), m) }) } else { enc = styxproto.NewEncoder(rwc) dec = styxproto.NewDecoder(rwc) } return &conn{ Decoder: dec, Encoder: enc, srv: srv, rwc: rwc, cx: context.TODO(), msize: msize, sessionFid: util.NewMap(), pendingReq: util.NewMap(), qidpool: qidpool.New(), } }
func TestDirectory(t *testing.T) { dirname, err := ioutil.TempDir("", "") if err != nil { t.Fatal(err) } defer os.RemoveAll(dirname) fd, err := os.Open(dirname) if err != nil { t.Error(err) return } for i := 0; i < 10; i++ { f, err := ioutil.TempFile(dirname, "dirtest") if err != nil { t.Error(err) } f.Close() } _, err = ioutil.TempDir(dirname, "dirtest-dir") if err != nil { t.Error(err) return } dir := NewDir(fd, dirname, qidpool.New()) // We know that we can read a single Stat by only // asking for 1 * MaxStatLen bytes. This is an implementation // detail that may not be true in the future. buf := make([]byte, styxproto.MaxStatLen) var offset int64 for { n, err := dir.ReadAt(buf, offset) if err == io.EOF { break } if err != nil { t.Error(err) break } offset += int64(n) stat := styxproto.Stat(buf) t.Logf("%s", stat) } }