// Serve listens on sock for new connections and services them.
func (server LinuxHostAdminServer) Serve(sock *net.UnixListener) error {
	defer RecoverTPMResources()
	// Set the socket to allow peer credentials to be passed
	sockFile, err := sock.File()
	if err != nil {
		return err
	}
	err = syscall.SetsockoptInt(int(sockFile.Fd()), syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1 /* true */)
	sockFile.Close()
	if err != nil {
		return err
	}

	connections := make(chan *net.UnixConn, 1)
	errors := make(chan error, 1)
	go func() {
		defer RecoverTPMResources()
		for {
			conn, err := sock.AcceptUnix()
			if err != nil {
				errors <- err
				break
			}
			connections <- conn
		}
	}()

	for {
		var conn *net.UnixConn
		select {
		case conn = <-connections:
			break
		case err = <-errors:
			return err
		case <-server.Done:
			return nil
		}
		s := rpc.NewServer()
		oob := util.NewOOBUnixConn(conn)
		err = s.RegisterName("LinuxHost", linuxHostAdminServerStub{oob, server.lh, server.Done})
		if err != nil {
			return err
		}
		go func() {
			defer RecoverTPMResources()
			s.ServeCodec(protorpc.NewServerCodec(oob))
		}()
	}
}
// Serve listens on sock for new connections and services them.
func (server LinuxHostAdminServer) Serve(sock *net.UnixListener) error {
	// Set the socket to allow peer credentials to be passed
	err := NewAuthenticatedFileSocket(sock)
	if err != nil {
		return err
	}

	connections := make(chan *net.UnixConn, 1)
	errors := make(chan error, 1)
	go func() {
		for {
			conn, err := sock.AcceptUnix()
			if err != nil {
				errors <- err
				break
			}
			connections <- conn
		}
	}()

	for {
		var conn *net.UnixConn
		select {
		case conn = <-connections:
			break
		case err = <-errors:
			return err
		case <-server.Done:
			return nil
		}
		s := rpc.NewServer()
		oob := util.NewOOBUnixConn(conn)
		err = s.RegisterName("LinuxHost", linuxHostAdminServerStub{oob, server.lh, server.Done})
		if err != nil {
			return err
		}
		go s.ServeCodec(protorpc.NewServerCodec(oob))
	}
}
// NewLinuxHostAdminClient returns a new client stub for LinuxHost's admin RPC
// interface.
func NewLinuxHostAdminClient(conn *net.UnixConn) LinuxHostAdminClient {
	oob := util.NewOOBUnixConn(conn)
	c := rpc.NewClientWithCodec(protorpc.NewClientCodec(oob))
	return LinuxHostAdminClient{oob, c}
}