Exemple #1
0
// NewSocketListener returns a new socket listener struct.
func NewSocketListener(socketPath string, handler ConnectionHandler) (*socketListener, error) {
	listener, err := sockets.Listen(socketPath)
	if err != nil {
		return nil, errors.Trace(err)
	}
	sListener := &socketListener{listener: listener, handler: handler}
	go func() {
		defer sListener.t.Done()
		sListener.t.Kill(sListener.loop())
	}()
	return sListener, nil
}
Exemple #2
0
// NewRunListener returns a new RunListener that is listening on given
// socket or named pipe passed in. If a valid RunListener is returned, is
// has the go routine running, and should be closed by the creator
// when they are done with it.
func NewRunListener(runner CommandRunner, socketPath string) (*RunListener, error) {
	server := rpc.NewServer()
	if err := server.Register(&JujuRunServer{runner}); err != nil {
		return nil, err
	}
	listener, err := sockets.Listen(socketPath)
	if err != nil {
		return nil, err
	}
	runListener := &RunListener{
		listener: listener,
		server:   server,
		closed:   make(chan struct{}),
		closing:  make(chan struct{}),
	}
	go runListener.Run()
	return runListener, nil
}
Exemple #3
0
// NewServer creates an RPC server bound to socketPath, which can execute
// remote command invocations against an appropriate Context. It will not
// actually do so until Run is called.
func NewServer(getCmd CmdGetter, socketPath string) (*Server, error) {
	server := rpc.NewServer()
	if err := server.Register(&Jujuc{getCmd: getCmd}); err != nil {
		return nil, err
	}
	listener, err := sockets.Listen(socketPath)
	if err != nil {
		return nil, err
	}
	s := &Server{
		socketPath: socketPath,
		listener:   listener,
		server:     server,
		closed:     make(chan bool),
		closing:    make(chan bool),
	}
	return s, nil
}
Exemple #4
0
// NewRunListener returns a new RunListener that is listening on given
// socket or named pipe passed in. If a valid RunListener is returned, is
// has the go routine running, and should be closed by the creator
// when they are done with it.
func NewRunListener(cfg RunListenerConfig) (*RunListener, error) {
	if err := cfg.Validate(); err != nil {
		return nil, errors.Trace(err)
	}
	listener, err := sockets.Listen(cfg.SocketPath)
	if err != nil {
		return nil, errors.Trace(err)
	}
	runListener := &RunListener{
		RunListenerConfig: cfg,
		listener:          listener,
		server:            rpc.NewServer(),
		closed:            make(chan struct{}),
		closing:           make(chan struct{}),
	}
	if err := runListener.server.Register(&JujuRunServer{runListener}); err != nil {
		return nil, errors.Trace(err)
	}
	go runListener.Run()
	return runListener, nil
}