Documentation
¶
Index ¶
- Constants
- func GetID(network, address string, seed int, logger zerolog.Logger) string
- func GetRLimit(logger zerolog.Logger) syscall.Rlimit
- func IsConnClosed(received int, err *gerr.GatewayDError) bool
- func IsConnTimedOut(err *gerr.GatewayDError) bool
- func Resolve(network, address string, logger zerolog.Logger) (string, *gerr.GatewayDError)
- type Client
- type ClientInterface
- type Proxy
- type ProxyImpl
- func (pr *ProxyImpl) Connect(gconn gnet.Conn) *gerr.GatewayDError
- func (pr *ProxyImpl) Disconnect(gconn gnet.Conn) *gerr.GatewayDError
- func (pr *ProxyImpl) IsExhausted() bool
- func (pr *ProxyImpl) IsHealty(client *Client) (*Client, *gerr.GatewayDError)
- func (pr *ProxyImpl) PassThrough(gconn gnet.Conn) *gerr.GatewayDError
- func (pr *ProxyImpl) Shutdown()
- type Server
- func (s *Server) IsRunning() bool
- func (s *Server) OnBoot(engine gnet.Engine) gnet.Action
- func (s *Server) OnClose(gconn gnet.Conn, err error) gnet.Action
- func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action)
- func (s *Server) OnShutdown(engine gnet.Engine)
- func (s *Server) OnTick() (time.Duration, gnet.Action)
- func (s *Server) OnTraffic(gconn gnet.Conn) gnet.Action
- func (s *Server) Run() error
- func (s *Server) Shutdown()
- type Status
Constants ¶
const ( DefaultSeed = 1000 DefaultChunkSize = 4096 DefaultReceiveDeadline = 0 // 0 means no deadline (timeout) DefaultSendDeadline = 0 DefaultTCPKeepAlivePeriod = 30 * time.Second )
const ( Running Status = "running" Stopped Status = "stopped" DefaultTickInterval = 5 * time.Second DefaultPoolSize = 10 MinimumPoolSize = 2 DefaultBufferSize = 1 << 24 // 16777216 bytes )
const (
EmptyPoolCapacity int = 0
)
Variables ¶
This section is empty.
Functions ¶
func GetRLimit ¶
GetRLimit returns the current system soft and hard limits for the number of open files.
func IsConnClosed ¶ added in v0.1.4
func IsConnClosed(received int, err *gerr.GatewayDError) bool
IsConnClosed returns true if the connection is closed.
func IsConnTimedOut ¶ added in v0.1.4
func IsConnTimedOut(err *gerr.GatewayDError) bool
IsConnTimedOut returns true if the error is a timeout error.
Types ¶
type Client ¶
type Client struct {
net.Conn
TCPKeepAlive bool
TCPKeepAlivePeriod time.Duration
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, tcpKeepAlive bool, tcpKeepAlivePeriod time.Duration, logger zerolog.Logger, ) *Client
NewClient creates a new client.
func (*Client) IsConnected ¶ added in v0.1.0
IsConnected checks if the client is still connected to the server.
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
IsHealty(cl *Client) (*Client, *gerr.GatewayDError)
IsExhausted() bool
Shutdown()
}
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
NewProxy creates a new proxy.
func (*ProxyImpl) Connect ¶
func (pr *ProxyImpl) Connect(gconn gnet.Conn) *gerr.GatewayDError
Connect maps a server connection from the available connection pool to a incoming connection. It returns an error if the pool is exhausted. If the pool is elastic, it creates a new client and maps it to the incoming connection.
func (*ProxyImpl) Disconnect ¶
func (pr *ProxyImpl) Disconnect(gconn gnet.Conn) *gerr.GatewayDError
Disconnect removes the client from the busy connection pool and tries to recycle the server connection.
func (*ProxyImpl) IsExhausted ¶ added in v0.1.0
IsExhausted checks if the available connection pool is exhausted.
func (*ProxyImpl) IsHealty ¶ added in v0.1.3
func (pr *ProxyImpl) IsHealty(client *Client) (*Client, *gerr.GatewayDError)
IsHealty checks if the pool is exhausted or the client is disconnected.
func (*ProxyImpl) PassThrough ¶
func (pr *ProxyImpl) PassThrough(gconn gnet.Conn) *gerr.GatewayDError
PassThrough sends the data from the client to the server and vice versa.
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
NewServer creates a new server.
func (*Server) OnBoot ¶
OnBoot is called when the server is booted. It calls the OnBooting and OnBooted hooks. It also sets the status to running, which is used to determine if the server should be running or shutdown.
func (*Server) OnClose ¶
OnClose is called when a connection is closed. It calls the OnClosing and OnClosed hooks. It also recycles the connection back to the available connection pool, unless the pool is elastic and reuse is disabled.
func (*Server) OnOpen ¶
OnOpen is called when a new connection is opened. It calls the OnOpening and OnOpened hooks. It also checks if the server is at the soft or hard limit and closes the connection if it is.
func (*Server) OnShutdown ¶
OnShutdown is called when the server is shutting down. It calls the OnShutdown hooks.
func (*Server) OnTraffic ¶
OnTraffic is called when data is received from the client. It calls the OnTraffic hooks. It then passes the traffic to the proxied connection.