multiplexing

package
v0.0.0-...-b66102c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package multiplexing defines the multiplex connection pool for sending request and receiving response. After receiving the response, the decoded response will be returned to the client. It is used for the communication with TubeMQ.

Index

Constants

View Source
const (
	Initial int = iota
	Connected
	Closing
	Closed
)

The state of the connection.

Variables

View Source
var (
	// ErrConnClosed indicates the connection has been closed
	ErrConnClosed = errors.New("connection has been closed")
	// ErrChanClosed indicates the recv chan has been closed
	ErrChanClosed = errors.New("unexpected recv chan closing")
	// ErrWriteBufferDone indicates write buffer done
	ErrWriteBufferDone = errors.New("write buffer done")
	// ErrAssertConnection indicates connection assertion error
	ErrAssertConnection = errors.New("connection assertion error")
)

Functions

This section is empty.

Types

type Connection

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

Connection represents the underlying TCP connection of the multiplex connections of an address and maintains the multiplex connections.

type DialOptions

type DialOptions struct {
	Network       string
	Address       string
	Timeout       time.Duration
	CACertFile    string
	TLSCertFile   string
	TLSKeyFile    string
	TLSServerName string
}

DialOptions represents the dail options of the TCP connection. If TLS is not enabled, the configuration of TLS can be ignored.

type MultiplexConnection

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

MultiplexConnection is used to multiplex a TCP connection. It is distinguished by the serialNo.

func (*MultiplexConnection) Read

func (mc *MultiplexConnection) Read() (codec.Response, error)

Read returns the response from the multiplex connection.

func (*MultiplexConnection) Write

func (mc *MultiplexConnection) Write(b []byte) error

Write uses the underlying TCP connection to send the bytes.

type Pool

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

Pool maintains the multiplex connections of different addresses.

func NewPool

func NewPool() *Pool

NewPool will construct a default multiplex connections pool.

func (*Pool) Close

func (p *Pool) Close()

Close will release all the connections.

func (*Pool) Get

func (p *Pool) Get(ctx context.Context, address string, serialNo uint32,
	opts *DialOptions) (*MultiplexConnection, error)

Get will return a multiplex connection 1. If no underlying TCP connection has been created, a TCP connection will be created first. 2. A new multiplex connection with the serialNo will be created and returned.

Jump to

Keyboard shortcuts

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