github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/sub/client/poll.go (about)

     1  package client
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/filesystem"
     7  	"github.com/Cloud-Foundations/Dominator/lib/objectcache"
     8  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
     9  	"github.com/Cloud-Foundations/Dominator/proto/sub"
    10  )
    11  
    12  func callPoll(client *srpc.Client, request sub.PollRequest,
    13  	reply *sub.PollResponse) error {
    14  	conn, err := client.Call("Subd.Poll")
    15  	if err != nil {
    16  		return err
    17  	}
    18  	defer conn.Close()
    19  	if err := conn.Encode(request); err != nil {
    20  		return err
    21  	}
    22  	conn.Flush()
    23  	str, err := conn.ReadString('\n')
    24  	if err != nil {
    25  		return err
    26  	}
    27  	if str != "\n" {
    28  		return errors.New(str[:len(str)-1])
    29  	}
    30  	if err := conn.Decode(reply); err != nil {
    31  		return err
    32  	}
    33  	if reply.FileSystemFollows {
    34  		reply.FileSystem, err = filesystem.Decode(conn)
    35  		if err != nil {
    36  			return err
    37  		}
    38  		reply.ObjectCache, err = objectcache.Decode(conn)
    39  		if err != nil {
    40  			return err
    41  		}
    42  	}
    43  	return nil
    44  }