func callPoll(client *srpc.Client, request sub.PollRequest, reply *sub.PollResponse) error { conn, err := client.Call("Subd.Poll") if err != nil { return err } defer conn.Close() encoder := gob.NewEncoder(conn) if err := encoder.Encode(request); err != nil { return err } conn.Flush() str, err := conn.ReadString('\n') if err != nil { return err } if str != "\n" { return errors.New(str) } if err := gob.NewDecoder(conn).Decode(reply); err != nil { return err } if reply.FileSystemFollows { reply.FileSystem, err = filesystem.Decode(conn) if err != nil { return err } reply.ObjectCache, err = objectcache.Decode(conn) if err != nil { return err } } return nil }
func newObjectAdderQueue(client *srpc.Client) (*ObjectAdderQueue, error) { var objQ ObjectAdderQueue var err error objQ.conn, err = client.Call("ObjectServer.AddObjects") if err != nil { return nil, err } objQ.encoder = gob.NewEncoder(objQ.conn) getResponseChan := make(chan bool, 65536) errorChan := make(chan error, 1024) objQ.getResponseChan = getResponseChan objQ.errorChan = errorChan objQ.sendSemaphore = make(chan bool, 1) go readResponses(objQ.conn, getResponseChan, errorChan) return &objQ, nil }
func listImages(client *srpc.Client) ([]string, error) { conn, err := client.Call("ImageServer.ListImages") if err != nil { return nil, err } defer conn.Close() images := make([]string, 0) for { line, err := conn.ReadString('\n') if err != nil { return nil, err } line = line[:len(line)-1] if line == "" { break } images = append(images, line) } return images, nil }
func listDirectories(client *srpc.Client) ([]image.Directory, error) { conn, err := client.Call("ImageServer.ListDirectories") if err != nil { return nil, err } defer conn.Close() directories := make([]image.Directory, 0) decoder := gob.NewDecoder(conn) for { var directory image.Directory if err := decoder.Decode(&directory); err != nil { return nil, err } if directory.Name == "" { break } directories = append(directories, directory) } return directories, nil }
func callFetch(client *srpc.Client, request sub.FetchRequest, reply *sub.FetchResponse) error { conn, err := client.Call("Subd.Fetch") if err != nil { return err } defer conn.Close() encoder := gob.NewEncoder(conn) if err := encoder.Encode(request); err != nil { return err } conn.Flush() str, err := conn.ReadString('\n') if err != nil { return err } if str != "\n" { return errors.New(str) } return gob.NewDecoder(conn).Decode(reply) }
func callAddImage(client *srpc.Client, request imageserver.AddImageRequest, reply *imageserver.AddImageResponse) error { conn, err := client.Call("ImageServer.AddImage") if err != nil { return err } defer conn.Close() encoder := gob.NewEncoder(conn) if err := encoder.Encode(request); err != nil { return err } conn.Flush() str, err := conn.ReadString('\n') if err != nil { return err } if str != "\n" { return errors.New(str) } return gob.NewDecoder(conn).Decode(reply) }
func listUnreferencedObjects(client *srpc.Client) ( map[hash.Hash]uint64, error) { conn, err := client.Call("ImageServer.ListUnreferencedObjects") if err != nil { return nil, err } defer conn.Close() objects := make(map[hash.Hash]uint64) decoder := gob.NewDecoder(conn) for { var object imageserver.Object if err := decoder.Decode(&object); err != nil { return nil, err } if object.Size < 1 { break } objects[object.Hash] = object.Size } return objects, nil }
func getFiles(client *srpc.Client, filenames []string, readerFunc func(reader io.Reader, size uint64) error) error { conn, err := client.Call("Subd.GetFiles") if err != nil { return err } defer conn.Close() go sendRequests(conn, filenames) decoder := gob.NewDecoder(conn) for range filenames { var reply sub.GetFileResponse if err := decoder.Decode(&reply); err != nil { return err } if reply.Error != nil { return reply.Error } if err := readerFunc(&io.LimitedReader{R: conn, N: int64(reply.Size)}, reply.Size); err != nil { return err } } return nil }