transport

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultMaxSleepTime           = 1 * time.Second  // accept中间最大sleep interval
	DefaultMAXConnNum             = 50 * 1024 * 1024 // 默认最大连接数 50w
	DefaultHTTPRspBufferSize      = 1024
	PathPrefix               byte = byte('/')
)
View Source
const (
	DefaultTCPReadBufferSize  = 256 * 1024
	DefaultTCPWriteBufferSize = 128 * 1024
)
View Source
const (
	REQ_Q_SIZE = 1 // http1.1形式的短连接,一次也只能处理一个请求,放大size无意义
)

Variables

View Source
var (
	DefaultDialTimeout = time.Second * 5
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Recv(*Package) error
	Send(*Package) error
	Close() error
}

type DialOption

type DialOption func(*DialOptions)

func WithPath

func WithPath(path string) DialOption

func WithStream

func WithStream() DialOption

Indicates whether this is a streaming connection

func WithTimeout

func WithTimeout(d time.Duration) DialOption

Timeout used when dialling the remote side

type DialOptions

type DialOptions struct {
	Stream  bool
	Timeout time.Duration
	Path    string

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type ListenOption

type ListenOption func(*ListenOptions)

type ListenOptions

type ListenOptions struct {

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Listener

type Listener interface {
	Addr() string
	Close() error
	Accept(func(Socket)) error
}

type NewTransport added in v0.2.0

type NewTransport func(...Option) Transport

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs to use for transport

func Timeout

func Timeout(t time.Duration) Option

Timeout sets the timeout for Send/Recv execution

type Options

type Options struct {
	Addrs []string
	// Timeout sets the timeout for Send/Recv
	Timeout time.Duration

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Package added in v0.2.0

type Package struct {
	Header map[string]string
	Body   []byte
}

func (*Package) Reset added in v0.2.0

func (m *Package) Reset()

type Socket

type Socket interface {
	Recv(*Package) error
	Send(*Package) error
	Reset(c net.Conn, release func())
	Close() error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
}

type Transport

type Transport interface {
	Options() *Options
	Dial(addr string, opts ...DialOption) (Client, error)
	Listen(addr string, opts ...ListenOption) (Listener, error)
	String() string
}

Transport is an interface which is used for communication between services. It uses socket send/recv semantics.

func NewHTTPTransport

func NewHTTPTransport(opts ...Option) Transport

just leave here to compatible with v0.1

func NewTCPTransport added in v0.2.0

func NewTCPTransport(opts ...Option) Transport

Jump to

Keyboard shortcuts

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