network

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSeed            = 1000
	DefaultChunkSize       = 4096
	DefaultReceiveDeadline = 0 // 0 means no deadline (timeout)
	DefaultSendDeadline    = 0
)
View Source
const (
	Running Status = "running"
	Stopped Status = "stopped"

	DefaultTickInterval = 5 * time.Second
	DefaultPoolSize     = 10
	MinimumPoolSize     = 2
	DefaultBufferSize   = 1 << 24 // 16777216 bytes
)
View Source
const (
	EmptyPoolCapacity int = 0
)

Variables

This section is empty.

Functions

func GetID

func GetID(network, address string, seed int, logger zerolog.Logger) string

func GetRLimit

func GetRLimit(logger zerolog.Logger) syscall.Rlimit

func Resolve added in v0.0.2

func Resolve(network, address string, logger zerolog.Logger) (string, *gerr.GatewayDError)

Types

type Client

type Client struct {
	net.Conn

	ReceiveBufferSize int
	ReceiveChunkSize  int
	ReceiveDeadline   time.Duration
	SendDeadline      time.Duration
	ID                string
	Network           string // tcp/udp/unix
	Address           string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(
	network, address string,
	receiveBufferSize, receiveChunkSize int,
	receiveDeadline, sendDeadline time.Duration,
	logger zerolog.Logger,
) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) IsConnected added in v0.1.0

func (c *Client) IsConnected() bool

func (*Client) Receive

func (c *Client) Receive() (int, []byte, *gerr.GatewayDError)

func (*Client) Send

func (c *Client) Send(data []byte) (int, *gerr.GatewayDError)

type ClientInterface added in v0.1.2

type ClientInterface interface {
	Send(data []byte) (int, *gerr.GatewayDError)
	Receive() (int, []byte, *gerr.GatewayDError)
	Close()
	IsConnected() bool
}

type Proxy

type Proxy interface {
	Connect(gconn gnet.Conn) *gerr.GatewayDError
	Disconnect(gconn gnet.Conn) *gerr.GatewayDError
	PassThrough(gconn gnet.Conn) *gerr.GatewayDError
	TryReconnect(cl *Client) (*Client, *gerr.GatewayDError)
	Shutdown()
	IsExhausted() bool
}

type ProxyImpl

type ProxyImpl struct {
	Elastic             bool
	ReuseElasticClients bool

	// ClientConfig is used for elastic proxy and reconnection
	ClientConfig *Client
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy(
	p pool.Pool, hookConfig *plugin.HookConfig,
	elastic, reuseElasticClients bool,
	clientConfig *Client, logger zerolog.Logger,
) *ProxyImpl

func (*ProxyImpl) Connect

func (pr *ProxyImpl) Connect(gconn gnet.Conn) *gerr.GatewayDError

func (*ProxyImpl) Disconnect

func (pr *ProxyImpl) Disconnect(gconn gnet.Conn) *gerr.GatewayDError

func (*ProxyImpl) IsExhausted added in v0.1.0

func (pr *ProxyImpl) IsExhausted() bool

func (*ProxyImpl) PassThrough

func (pr *ProxyImpl) PassThrough(gconn gnet.Conn) *gerr.GatewayDError

func (*ProxyImpl) Shutdown

func (pr *ProxyImpl) Shutdown()

func (*ProxyImpl) TryReconnect added in v0.1.0

func (pr *ProxyImpl) TryReconnect(client *Client) (*Client, *gerr.GatewayDError)

type Server

type Server struct {
	gnet.BuiltinEventEngine

	Network      string // tcp/udp/unix
	Address      string
	Options      []gnet.Option
	SoftLimit    uint64
	HardLimit    uint64
	Status       Status
	TickInterval time.Duration
	// contains filtered or unexported fields
}

func NewServer added in v0.0.2

func NewServer(
	network, address string,
	softLimit, hardLimit uint64,
	tickInterval time.Duration,
	options []gnet.Option,
	proxy Proxy,
	logger zerolog.Logger,
	hooksConfig *plugin.HookConfig,
) *Server

func (*Server) IsRunning added in v0.0.2

func (s *Server) IsRunning() bool

func (*Server) OnBoot

func (s *Server) OnBoot(engine gnet.Engine) gnet.Action

func (*Server) OnClose

func (s *Server) OnClose(gconn gnet.Conn, err error) gnet.Action

func (*Server) OnOpen

func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action)

func (*Server) OnShutdown

func (s *Server) OnShutdown(engine gnet.Engine)

func (*Server) OnTick

func (s *Server) OnTick() (time.Duration, gnet.Action)

func (*Server) OnTraffic

func (s *Server) OnTraffic(gconn gnet.Conn) gnet.Action

func (*Server) Run

func (s *Server) Run() error

func (*Server) Shutdown

func (s *Server) Shutdown()

type Status added in v0.0.2

type Status string

Jump to

Keyboard shortcuts

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