control

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package control is the bridge's control channel: a per-session local socket (or named pipe on Windows) the daemon hub accepts on and the bridge dials.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScanEvents

func ScanEvents(r io.Reader, fn func(contracts.Event) error) error

ScanEvents reads JSON-line events from r, calling fn for each. A blank line is skipped; a line starting with '{' MUST parse as a JSON Event or it is a protocol error (returned, not surfaced as a pick); a non-'{' line is treated as the legacy bare pick value and surfaced as Event{T:"pick", Value:line} for back-compat. It returns the first fn error, a malformed-line error, or a read error other than io.EOF.

func SocketPath

func SocketPath(session string) string

func WriteEvent

func WriteEvent(w io.Writer, e contracts.Event) error

WriteEvent encodes e as a single JSON line (newline-terminated). encoding/json escapes any newline inside a field, so one Event is always one line.

Types

type Acceptor

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

Acceptor listens on a control socket and yields one persistent Conn per dialing bridge, keeping each connection open for the session's life.

func Accept

func Accept(path string) (*Acceptor, error)

Accept binds the control socket at path (removing a stale socket first) and starts accepting bridge connections. Each appears on Conns().

func (*Acceptor) Close

func (a *Acceptor) Close() error

Close stops listening and removes the socket file.

func (*Acceptor) Conns

func (a *Acceptor) Conns() <-chan *Conn

Conns yields each bridge connection; it closes when the Acceptor is closed.

type Conn

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

Conn is a persistent bidirectional event connection over a net.Conn. The daemon (hub) accepts one per supervised bridge; the bridge dials. Each direction is an independent stream of JSON-line Events. Write is safe for concurrent callers (serialized by mu); Scan must be called from a single goroutine.

func Dial

func Dial(path string) (*Conn, error)

Dial connects to the hub's control socket, returning a persistent Conn. The bridge calls this at startup and again on each reconnect.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Emit

func (c *Conn) Emit(e contracts.Event)

Emit satisfies contracts.EventSink so the bridge can hand a Conn directly to its turn loop as the event sink. A write error is dropped: emission is best-effort and the hub's read side detects a dead conn independently.

func (*Conn) Scan

func (c *Conn) Scan(fn func(contracts.Event) error) error

Scan reads events until the peer closes the connection or fn returns an error, calling fn for each. A clean peer close (io.EOF) yields nil; fn's error (or a malformed-line / read error) is returned otherwise.

func (*Conn) Write

func (c *Conn) Write(e contracts.Event) error

Write sends one Event as a JSON line.

Jump to

Keyboard shortcuts

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