srv

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseServerHandler

type BaseServerHandler struct {
}

func (*BaseServerHandler) Boot

func (b *BaseServerHandler) Boot(_ BootServer, traverse TraverseBy) error

func (*BaseServerHandler) Close

func (b *BaseServerHandler) Close(_ trp.Channel, traverse TraverseBy) error

func (*BaseServerHandler) Error

func (b *BaseServerHandler) Error(_ trp.Channel, _ error, traverse TraverseBy)

func (*BaseServerHandler) Open

func (b *BaseServerHandler) Open(_ trp.Channel, traverse TraverseBy) error

func (*BaseServerHandler) Reader

func (b *BaseServerHandler) Reader(_ trp.Channel, traverse TraverseBy) error

type BootServer

type BootServer interface {
	Start(opt ...ServerOption) error
}

type ConnContext

type ConnContext struct {
	Id string

	IsTimeOut bool
	// contains filtered or unexported fields
}

func NewConnContext

func NewConnContext(isUdp bool, addr string) *ConnContext

func (*ConnContext) AddAttr

func (receiver *ConnContext) AddAttr(key lang.KeyType, value interface{})

func (*ConnContext) GetAttr

func (receiver *ConnContext) GetAttr(key lang.KeyType) (interface{}, bool)

func (*ConnContext) GetLastActive

func (receiver *ConnContext) GetLastActive() time.Time

func (*ConnContext) LastActive

func (receiver *ConnContext) LastActive()

type DupServer

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

func NewDupServer

func NewDupServer(port int, opt ...ServerOption) *DupServer

func (*DupServer) AddHandler

func (sever *DupServer) AddHandler(handler ...ServerHandler)

func (*DupServer) OnClose

func (sever *DupServer) OnClose(conn trp.Channel)

func (*DupServer) OnError

func (sever *DupServer) OnError(conn trp.Channel, err error)

func (*DupServer) OnOpen

func (sever *DupServer) OnOpen(conn trp.Channel) error

func (*DupServer) OnRead

func (sever *DupServer) OnRead(conn trp.Channel) error

func (*DupServer) Shutdown

func (sever *DupServer) Shutdown(ctx context.Context)

func (*DupServer) Start

func (sever *DupServer) Start() error

type GChannel

type GChannel struct {
	Context *ConnContext

	Server *Server
	// contains filtered or unexported fields
}

GChannel @Description:

func NewChannel

func NewChannel(conn gnet.Conn, t *Server) *GChannel

func (*GChannel) ActiveTime

func (c *GChannel) ActiveTime() time.Time

func (*GChannel) Close

func (c *GChannel) Close() error

func (*GChannel) Discard

func (c *GChannel) Discard(pos int) (discarded int, err error)

func (*GChannel) Done

func (c *GChannel) Done() <-chan struct{}

func (*GChannel) GetAttr

func (c *GChannel) GetAttr(key lang.KeyType) (interface{}, bool)

func (*GChannel) GetConn

func (c *GChannel) GetConn() net.Conn

func (*GChannel) GetContext

func (c *GChannel) GetContext() *ConnContext

func (*GChannel) GetId

func (c *GChannel) GetId() string

func (*GChannel) GetNetConn

func (c *GChannel) GetNetConn() net.Conn

func (*GChannel) GetReader

func (c *GChannel) GetReader() io.Reader

func (*GChannel) GetServer

func (c *GChannel) GetServer() *Server

func (*GChannel) GetWriter

func (c *GChannel) GetWriter() io.Writer

func (*GChannel) IsClose

func (c *GChannel) IsClose() bool

func (*GChannel) IsHealthy added in v0.4.0

func (c *GChannel) IsHealthy() bool

func (*GChannel) LastTime

func (c *GChannel) LastTime() time.Time

func (*GChannel) LocalAddr

func (c *GChannel) LocalAddr() net.Addr

func (*GChannel) Next

func (c *GChannel) Next(pos int) ([]byte, error)

func (*GChannel) OnClose

func (c *GChannel) OnClose(event transport.CloseEvent)

func (*GChannel) Peek

func (c *GChannel) Peek(n int) (buf []byte, err error)

func (*GChannel) Read

func (c *GChannel) Read(out []byte) (int, error)

func (*GChannel) ReadFull

func (c *GChannel) ReadFull(out []byte) (int, error)

func (*GChannel) RemoteAddr

func (c *GChannel) RemoteAddr() net.Addr

func (*GChannel) SendTo

func (c *GChannel) SendTo(by []byte, addr net.Addr) (int, error)

func (*GChannel) SetDeadline

func (c *GChannel) SetDeadline(t time.Time) error

SetDeadline is a wrapper for gnet.conn.SetDeadline.

func (*GChannel) SetReadDeadline

func (c *GChannel) SetReadDeadline(t time.Time) error

func (*GChannel) SetWriteDeadline

func (c *GChannel) SetWriteDeadline(t time.Time) error

func (*GChannel) Write

func (c *GChannel) Write(out []byte) (int, error)

type GContext

type GContext interface {
	GetContext() *ConnContext

	Peek(pos int) ([]byte, error)

	Next(pos int) ([]byte, error)

	Discard(pos int) (discarded int, err error)
}

type InitConnHandler

type InitConnHandler func(conn *GChannel)

type NewChannelFunction

type NewChannelFunction func(ch transport.Channel) transport.Channel

type Server

type Server struct {
	*gnet.BuiltinEventEngine

	InitConnHandler InitConnHandler
	// contains filtered or unexported fields
}

Server /*

func NewServer

func NewServer(port int) *Server

func (*Server) AddHandler

func (sever *Server) AddHandler(handler ...ServerHandler)

func (*Server) AddInitConnHandler

func (sever *Server) AddInitConnHandler(init InitConnHandler)

func (*Server) Connections

func (sever *Server) Connections() map[string]*GChannel

func (*Server) GetConnection

func (sever *Server) GetConnection(id string) (*GChannel, bool)

func (*Server) GetPort

func (sever *Server) GetPort() int

func (*Server) OnBoot

func (sever *Server) OnBoot(engine gnet.Engine) (action gnet.Action)

func (*Server) OnClose

func (sever *Server) OnClose(c gnet.Conn, _ error) gnet.Action

func (*Server) OnOpen

func (sever *Server) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)

func (*Server) OnTraffic

func (sever *Server) OnTraffic(c gnet.Conn) gnet.Action

func (*Server) Shutdown

func (sever *Server) Shutdown(ctx context.Context)

func (*Server) Start

func (sever *Server) Start(opt ...ServerOption) error

Start is function start tcp server.

type ServerHandler

type ServerHandler interface {
	//
	// Close
	//  @Description: Shutdown conn notify.
	//  @param conn
	//
	Close(ch trp.Channel, traverse TraverseBy) error

	//
	// Open
	//  @Description: Open conn notify.
	//  @param conn
	//
	Open(ch trp.Channel, traverse TraverseBy) error

	//
	// Reader
	//  @Description: Reader conn data notify.
	//  @param conn
	//
	Reader(ch trp.Channel, traverse TraverseBy) error

	Error(ch trp.Channel, error error, traverse TraverseBy)

	Boot(server BootServer, traverse TraverseBy) error
}

type ServerOption

type ServerOption func(opts *sOptions)

func WithNetwork

func WithNetwork(pt lang.Network) ServerOption

WithNetwork WithProtocol This function takes a string parameter and returns a ServerOption

func WithNewChannelFunc

func WithNewChannelFunc(nfunc NewChannelFunction) ServerOption

func WithServerSmux

func WithServerSmux(smux *SmuxServerOption) ServerOption

WithServerSmux

@Description:
@param smux
@return ServerOption

func WithTimeout

func WithTimeout(timeout time.Duration) ServerOption

WithTimeout

@Description:
@param timeout
@return ServerOption

type SmuxServerOption

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

SmuxServerOption @Description:

func DefaultServerSmux

func DefaultServerSmux() *SmuxServerOption

type TraverseBy

type TraverseBy func()

Jump to

Keyboard shortcuts

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