smux: github.com/xtaci/smux Index | Files

package smux

import "github.com/xtaci/smux"

Package smux is a multiplexing library for Golang.

It relies on an underlying connection to provide reliability and ordering, such as TCP or KCP, and provides stream-oriented multiplexing over a single channel.

Index

Package Files

alloc.go frame.go mux.go session.go shaper.go stream.go

func VerifyConfig Uses

func VerifyConfig(config *Config) error

VerifyConfig is used to verify the sanity of configuration

type Allocator Uses

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

Allocator for incoming frames, optimized to prevent overwriting after zeroing

func NewAllocator Uses

func NewAllocator() *Allocator

NewAllocator initiates a []byte allocator for frames less than 65536 bytes, the waste(memory fragmentation) of space allocation is guaranteed to be no more than 50%.

func (*Allocator) Get Uses

func (alloc *Allocator) Get(size int) []byte

Get a []byte from pool with most appropriate cap

func (*Allocator) Put Uses

func (alloc *Allocator) Put(buf []byte) error

Put returns a []byte to pool for future use, which the cap must be exactly 2^n

type Config Uses

type Config struct {
    // KeepAliveInterval is how often to send a NOP command to the remote
    KeepAliveInterval time.Duration

    // KeepAliveTimeout is how long the session
    // will be closed if no data has arrived
    KeepAliveTimeout time.Duration

    // MaxFrameSize is used to control the maximum
    // frame size to sent to the remote
    MaxFrameSize int

    // MaxReceiveBuffer is used to control the maximum
    // number of data in the buffer pool
    MaxReceiveBuffer int
}

Config is used to tune the Smux session

func DefaultConfig Uses

func DefaultConfig() *Config

DefaultConfig is used to return a default configuration

type Frame Uses

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

Frame defines a packet from or to be multiplexed into a single connection

type Session Uses

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

Session defines a multiplexed connection for streams

func Client Uses

func Client(conn io.ReadWriteCloser, config *Config) (*Session, error)

Client is used to initialize a new client-side connection.

func Server Uses

func Server(conn io.ReadWriteCloser, config *Config) (*Session, error)

Server is used to initialize a new server-side connection.

func (*Session) AcceptStream Uses

func (s *Session) AcceptStream() (*Stream, error)

AcceptStream is used to block until the next available stream is ready to be accepted.

func (*Session) Close Uses

func (s *Session) Close() error

Close is used to close the session and all streams.

func (*Session) IsClosed Uses

func (s *Session) IsClosed() bool

IsClosed does a safe check to see if we have shutdown

func (*Session) LocalAddr Uses

func (s *Session) LocalAddr() net.Addr

LocalAddr satisfies net.Conn interface

func (*Session) NumStreams Uses

func (s *Session) NumStreams() int

NumStreams returns the number of currently open streams

func (*Session) OpenStream Uses

func (s *Session) OpenStream() (*Stream, error)

OpenStream is used to create a new stream

func (*Session) RemoteAddr Uses

func (s *Session) RemoteAddr() net.Addr

RemoteAddr satisfies net.Conn interface

func (*Session) SetDeadline Uses

func (s *Session) SetDeadline(t time.Time) error

SetDeadline sets a deadline used by Accept* calls. A zero time value disables the deadline.

type Stream Uses

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

Stream implements net.Conn

func (*Stream) Close Uses

func (s *Stream) Close() error

Close implements net.Conn

func (*Stream) GetDieCh Uses

func (s *Stream) GetDieCh() <-chan struct{}

GetDieCh returns a readonly chan which can be readable when the stream is to be closed.

func (*Stream) ID Uses

func (s *Stream) ID() uint32

ID returns the unique stream ID.

func (*Stream) LocalAddr Uses

func (s *Stream) LocalAddr() net.Addr

LocalAddr satisfies net.Conn interface

func (*Stream) Read Uses

func (s *Stream) Read(b []byte) (n int, err error)

Read implements net.Conn

func (*Stream) RemoteAddr Uses

func (s *Stream) RemoteAddr() net.Addr

RemoteAddr satisfies net.Conn interface

func (*Stream) SetDeadline Uses

func (s *Stream) SetDeadline(t time.Time) error

SetDeadline sets both read and write deadlines as defined by net.Conn.SetDeadline. A zero time value disables the deadlines.

func (*Stream) SetReadDeadline Uses

func (s *Stream) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline as defined by net.Conn.SetReadDeadline. A zero time value disables the deadline.

func (*Stream) SetWriteDeadline Uses

func (s *Stream) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline as defined by net.Conn.SetWriteDeadline. A zero time value disables the deadline.

func (*Stream) Write Uses

func (s *Stream) Write(b []byte) (n int, err error)

Write implements net.Conn

Package smux imports 9 packages (graph) and is imported by 31 packages. Updated 2019-09-11. Refresh now. Tools for package owners.