transport

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acceptor

type Acceptor interface {
	Accept() (Transport, error)
	Close() error
}

Acceptor defines transport acceptor

type Addr

type Addr = net.Addr

Addr alias to net.Addr

type Buffers

type Buffers struct {
	// [[..], [...], [...], [....]]
	Buffers net.Buffers
	// [2, 5, 8, 12]
	Indexes []int
}

Buffers to optimize message merging 用于优化消息的发送 1. 利用net.Buffers的接口实现Writev的系统调用优化 2. 免除合并buffer时导致的多余内存分配和内存考虑消耗 tcp中最常见的协议头一般需要在最后发送之前在头部追加协议头,通常需要分配一个 (sizeof(协议头) + sizeof(payload))的内存用于拼接最终的协议包用于发送 这里使用索引的方式标记出包与包的界限,这样就可以免除合并操作,可以极大的降低发送开销 下图中Buffers中的一个.(点)代表一个[]byte,[..] 通常代表[header, payload] [ [(header), (payload)], [(header), (payload1), (payload2)] ]

2                                 5

type BuffersWriter

type BuffersWriter interface {
	Writev(buffs Buffers) (int64, error)
}

BuffersWriter defines writev for optimized syscall

type Factory

type Factory interface {

	// Schemes supported schemes.
	Schemes() Schemes

	// Connect to the peer with the specified address.
	Connect(options *Options) (Transport, error)

	// Listen for an address and accept the connection request.
	Listen(options *Options) (Acceptor, error)
}

Factory defines transport factory

type Option

type Option func(options *Options) error

Option defines option function

func WithContext

func WithContext(ctx context.Context) Option

WithContext to hold other configure pass by context.WithValue

type Options

type Options struct {
	// In server side: listen address.
	// In client side: connect address.
	Address *url.URL

	// other configure pass by context.WithValue
	Context context.Context
}

Options for transport

func ParseOptions

func ParseOptions(ctx context.Context, url string, options ...Option) (*Options, error)

ParseOptions parse options

func (*Options) AddressWithoutHost

func (lo *Options) AddressWithoutHost() string

AddressWithoutHost convert host:port to :port

func (*Options) Apply

func (lo *Options) Apply(options ...Option) error

Apply options

type Schemes

type Schemes []string

Schemes to define scheme list

func (Schemes) Add

func (ss Schemes) Add(scheme string) Schemes

Add scheme

func (Schemes) FixedURL

func (ss Schemes) FixedURL(u *url.URL) error

FixedURL to fix scheme

func (Schemes) Valid

func (ss Schemes) Valid(scheme string) bool

Valid scheme

func (Schemes) ValidURL

func (ss Schemes) ValidURL(address string) bool

ValidURL to check url scheme

type Transport

type Transport interface {
	net.Conn

	// BuffersWriter for optimized syscall
	BuffersWriter

	// Flush flush buffer.
	Flush() error

	// RawTransport raw transport object.
	RawTransport() interface{}
}

Transport defines a transport

func BufferedTransport

func BufferedTransport(transport Transport, sizeRead int) Transport

BufferedTransport for optimize system calls with bufio.Reader

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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