wslconn

package
v0.11.0-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Status_Init         = "init"
	Status_Connecting   = "connecting"
	Status_Connected    = "connected"
	Status_Disconnected = "disconnected"
	Status_Error        = "error"
)
View Source
const DefaultConnectionTimeout = 60 * time.Second

Variables

View Source
var ConnServerCmdTemplate = strings.TrimSpace(
	strings.Join([]string{
		"%s version 2> /dev/null || (echo -n \"not-installed \"; uname -sm);",
		"exec %s connserver --router",
	}, "\n"))

Functions

func CpWshToRemote

func CpWshToRemote(ctx context.Context, client *wsl.Distro, clientOs string, clientArch string) error

func DisconnectClient

func DisconnectClient(connName string) error

func EnsureConnection

func EnsureConnection(ctx context.Context, connName string) error

Convenience function for ensuring a connection is established

func GetAllConnStatus

func GetAllConnStatus() []wshrpc.ConnStatus

func GetClientPlatform

func GetClientPlatform(ctx context.Context, shell genconn.ShellClient) (string, string, error)

returns (os, arch, error) guaranteed to return a supported platform

func GetClientPlatformFromOsArchStr

func GetClientPlatformFromOsArchStr(ctx context.Context, osArchStr string) (string, string, error)

func GetNumWSLHasConnected

func GetNumWSLHasConnected() int

func IsPowershell

func IsPowershell(shellPath string) bool

func WithLockRtn

func WithLockRtn[T any](conn *WslConn, fn func() T) T

Types

type CancellableCmd

type CancellableCmd struct {
	Cmd    *wsl.WslCmd
	Cancel func()
}

type WshCheckResult

type WshCheckResult struct {
	WshEnabled    bool
	ClientVersion string
	NoWshReason   string
	WshError      error
}

type WshInstallOpts

type WshInstallOpts struct {
	Force        bool
	NoUserPrompt bool
}

type WslConn

type WslConn struct {
	Lock               *sync.Mutex
	Status             string
	WshEnabled         *atomic.Bool
	Name               wsl.WslName
	Client             *wsl.Distro
	DomainSockName     string // if "", then no domain socket
	DomainSockListener net.Listener
	ConnController     *wsl.WslCmd
	Error              string
	WshError           string
	NoWshReason        string
	WshVersion         string
	HasWaiter          *atomic.Bool
	LastConnectTime    int64
	ActiveConnNum      int
	// contains filtered or unexported fields
}

func GetWslConn

func GetWslConn(name string) *WslConn

func (*WslConn) ClearWshError

func (conn *WslConn) ClearWshError()

func (*WslConn) Close

func (conn *WslConn) Close() error

func (*WslConn) Connect

func (conn *WslConn) Connect(ctx context.Context) error

does not return an error since that error is stored inside of WslConn

func (*WslConn) Debugf

func (conn *WslConn) Debugf(ctx context.Context, format string, args ...any)

func (*WslConn) DeriveConnStatus

func (conn *WslConn) DeriveConnStatus() wshrpc.ConnStatus

func (*WslConn) FireConnChangeEvent

func (conn *WslConn) FireConnChangeEvent()

func (*WslConn) GetClient

func (conn *WslConn) GetClient() *wsl.Distro

func (*WslConn) GetConfigShellPath

func (conn *WslConn) GetConfigShellPath() string

func (*WslConn) GetDomainSocketName

func (conn *WslConn) GetDomainSocketName() string

func (*WslConn) GetName

func (conn *WslConn) GetName() string

func (*WslConn) GetStatus

func (conn *WslConn) GetStatus() string

func (*WslConn) Infof

func (conn *WslConn) Infof(ctx context.Context, format string, args ...any)

func (*WslConn) InstallWsh

func (conn *WslConn) InstallWsh(ctx context.Context, osArchStr string) error

func (*WslConn) OpenDomainSocketListener

func (conn *WslConn) OpenDomainSocketListener(ctx context.Context) error

*

  • This function is does not set a listener for WslConn
  • It is still required in order to set SockName

*

func (*WslConn) Reconnect

func (conn *WslConn) Reconnect(ctx context.Context) error

func (*WslConn) SetWshError

func (conn *WslConn) SetWshError(err error)

func (*WslConn) StartConnServer

func (conn *WslConn) StartConnServer(ctx context.Context, afterUpdate bool) (bool, string, string, error)

returns (needsInstall, clientVersion, osArchStr, error) if wsh is not installed, the clientVersion will be "not-installed", and it will also return an osArchStr if clientVersion is set, then no osArchStr will be returned

func (*WslConn) UpdateWsh

func (conn *WslConn) UpdateWsh(ctx context.Context, clientDisplayName string, remoteInfo *wshrpc.RemoteInfo) error

func (*WslConn) WaitForConnect

func (conn *WslConn) WaitForConnect(ctx context.Context) error

func (*WslConn) WithLock

func (conn *WslConn) WithLock(fn func())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL