mux

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mux implements the ISO-8583 switch: it multiplexes request/response exchanges over a single full-duplex link.Link, correlating each response to its in-flight request by a caller-supplied key (typically STAN + terminal). A background reader dispatches frames to waiting callers; unmatched frames go to an optional unsolicited handler. (Named "mux" rather than "switch" because switch is a Go keyword and cannot be an import identifier.)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout      = errors.New("mux: request timed out")
	ErrClosed       = errors.New("mux: closed")
	ErrDuplicateKey = errors.New("mux: a request with this key is already in flight")
)

Mux errors.

Functions

This section is empty.

Types

type Keyer

type Keyer func(msg []byte) (string, error)

Keyer extracts a correlation key from a message frame. The key for a request and its response must match.

func FieldKeyer

func FieldKeyer(c *iso8583.Codec, des ...int) Keyer

FieldKeyer builds a Keyer that decodes a frame with c and joins the string values of the given data elements (e.g. DE 11 STAN + DE 41 terminal) — the standard ISO-8583 request/response correlation key.

type Mux

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

Mux correlates requests and responses over a link.

func New

func New(l *link.Link, key Keyer, opts ...Option) *Mux

New starts a Mux over l, beginning the background read loop immediately.

func (*Mux) Close

func (m *Mux) Close() error

Close stops the read loop, closes the link, and unblocks pending requests.

func (*Mux) Done added in v0.2.0

func (m *Mux) Done() <-chan struct{}

Done returns a channel closed when the mux stops — because Close was called or the underlying link's read loop failed. A supervisor (e.g. a reconnecting connector) selects on it to learn the link died without issuing a request.

func (*Mux) Err added in v0.2.0

func (m *Mux) Err() error

Err returns the cause once Done is closed: the read-loop error that downed the link, or ErrClosed if it was closed cleanly. It returns nil while still live.

func (*Mux) Request

func (m *Mux) Request(ctx context.Context, req []byte) ([]byte, error)

Request sends req and waits for the response whose key matches req's key, honouring ctx and the configured timeout.

type Option

type Option func(*config)

Option configures a Mux.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the default per-request timeout (0 = none; rely on context).

func WithUnsolicitedHandler

func WithUnsolicitedHandler(h func([]byte)) Option

WithUnsolicitedHandler sets a handler for frames that match no in-flight request (server-initiated requests, late responses). It runs on the reader goroutine, so it must not block.

Jump to

Keyboard shortcuts

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