wsconncache

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package wsconncache caches workspace agent connections by UUID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func New

func New(dialer Dialer, inactiveTimeout time.Duration) *Cache

New creates a new workspace connection cache that closes connections after the inactive timeout provided.

Agent connections are cached due to WebRTC negotiation taking a few hundred milliseconds.

func (*Cache) Acquire

func (c *Cache) Acquire(r *http.Request, id uuid.UUID) (*Conn, func(), error)

Acquire gets or establishes a connection with the dialer using the ID provided. If a connection is in-progress, that connection or error will be returned.

The returned function is used to release a lock on the connection. Once zero locks exist on a connection, the inactive timeout will begin to tick down. After the time expires, the connection will be cleared from the cache.

func (*Cache) Close

func (c *Cache) Close() error

type Conn

type Conn struct {
	*codersdk.AgentConn
	// contains filtered or unexported fields
}

Conn wraps an agent connection with a reusable HTTP transport.

func (*Conn) CloseWithError

func (c *Conn) CloseWithError(err error) error

CloseWithError ends the HTTP transport if exists, and closes the agent.

func (*Conn) HTTPTransport

func (c *Conn) HTTPTransport() *http.Transport

type Dialer

type Dialer func(r *http.Request, id uuid.UUID) (*codersdk.AgentConn, error)

Dialer creates a new agent connection by ID.

Jump to

Keyboard shortcuts

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