Commit a4b4a175 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e6e5b9ec
......@@ -67,6 +67,14 @@ type TreeSrv struct {
head zodb.Tid // last made commit
}
// AllStructsSrv represents connection to running `treegen allstructs.srv` server.
//
// Create it with StartAllStructsSrv().
// - AllStructs(maxdepth, maxsplit, n, seed, kv1, kv2)
type AllStructsSrv struct {
*TreeGenSrv
}
// StartTreeGenSrv spawns `treegen ...` server.
func StartTreeGenSrv(argv ...string) (_ *TreeGenSrv, hello string, err error) {
defer xerr.Contextf(&err, "treesrv %v: start", argv)
......@@ -105,15 +113,13 @@ func StartTreeGenSrv(argv ...string) (_ *TreeGenSrv, hello string, err error) {
return nil, "", err
}
hello = strings.TrimSuffix(hello, "\n")
defer xerr.Contextf(&err, "invalid hello %q", hello)
return tg, hello, nil
}
// StartTreeSrv spawns `treegen trees` server.
func StartTreeSrv(zurl string) (_ *TreeSrv, err error) {
defer xerr.Contextf(&err, "treesrv %s: start", zurl)
defer xerr.Contextf(&err, "tree.srv %s: start", zurl)
tgSrv, hello, err := StartTreeGenSrv("trees", zurl)
if err != nil {
return nil, err
......@@ -125,9 +131,9 @@ func StartTreeSrv(zurl string) (_ *TreeSrv, err error) {
tgSrv.Close() // ignore error
}
}()
defer xerr.Context(&err, "handshake")
// tree.srv start @<at> tree=<root>
defer xerr.Contextf(&err, "invalid hello %q", hello)
startRe := regexp.MustCompile(`^tree.srv start @([^ ]+) root=([^ ]+)$`)
m := startRe.FindStringSubmatch(hello)
if m == nil {
......@@ -145,6 +151,30 @@ func StartTreeSrv(zurl string) (_ *TreeSrv, err error) {
return tg, nil
}
// StartAllStructsSrv spwans `treegen allstructs.srv` server.
func StartAllStructsSrv() (_ *AllStructsSrv, err error) {
defer xerr.Context(&err, "allstructs.srv: start")
tgSrv, hello, err := StartTreeGenSrv("allstructs.srv")
if err != nil {
return nil, err
}
sg := &AllStructsSrv{TreeGenSrv: tgSrv}
defer func() {
if err != nil {
tgSrv.Close() // ignore error
}
}()
defer xerr.Contextf(&err, "invalid hello %q", hello)
if hello != "# allstructs.srv startQ" {
return nil, fmt.Errorf("unexpected format")
}
return sg, nil
}
// Close shutdowns treegen server.
func (tg *TreeGenSrv) Close() (err error) {
defer xerr.Contextf(&err, "treegen %v: close", tg.argv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment