service

package
v0.0.0-...-9493ce7 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCPSessionModeChunk  = TCPSessionMode(iota) // 块模式
	TCPSessionModeStream                        // 流模式
)

Variables

View Source
var (
	ErrServerAddress = errors.New("server address error") // 服务器地址错误
)

错误定义

Functions

This section is empty.

Types

type DataCallback

type DataCallback func(session *TCPSession, chunk []byte)

数据回调

type ErrCallback

type ErrCallback func(session *TCPSession, isRead bool, err error)

错误回调

type HTTPService

type HTTPService struct {
	*HTTPServiceConfig

	Router *fasthttprouter.Router
	// contains filtered or unexported fields
}

HTTPService HTTP服务

func NewHTTPService

func NewHTTPService(config *HTTPServiceConfig) *HTTPService

NewHTTPService 工厂方法

func (*HTTPService) Shutdown

func (object *HTTPService) Shutdown() (err error)

Shutdown 关闭

func (*HTTPService) Start

func (object *HTTPService) Start() (err error)

Start 启动

type HTTPServiceConfig

type HTTPServiceConfig struct {
	HTTPAddr           string // HTTP地址
	HTTPStaticLocation string // HTTP静态文件路径(URL)
	HTTPStaticPath     string // HTTP静态文件本地路径
	HTTPSAddr          string // HTTPS地址
	HTTPSCertPath      string // HTTP证书
	HTTPSKeyPath       string // HTTP Key
}

HTTPServiceConfig HTTP服务器配置

type NewSessionCallback

type NewSessionCallback func(session *TCPSession) (blocked bool)

新建会话回调

type TCPService

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

TCPService TCP服务

func NewTCPService

func NewTCPService() *TCPService

工厂方法

func NewTCPServiceWithCallback

func NewTCPServiceWithCallback(newSessionCallback NewSessionCallback) *TCPService

工厂方法

func (*TCPService) IsStopped

func (object *TCPService) IsStopped() bool

IsStopped 是否已停止

func (*TCPService) Start

func (object *TCPService) Start() (err error)

Start 启动

func (*TCPService) StartWithAddr

func (object *TCPService) StartWithAddr(addr string) (err error)

StartWithAddr 启动

func (*TCPService) Stop

func (object *TCPService) Stop()

Stop 停止

type TCPSession

type TCPSession struct {
	auto_lock.AutoLock

	ID int // 会话id

	Mode TCPSessionMode // 模式
	C    net.Conn       // TCP连接
	// contains filtered or unexported fields
}

TCPSession TCP会话

func NewTCPSession

func NewTCPSession() *TCPSession

NewTCPSession 工厂方法

func (*TCPSession) AddCallback

func (object *TCPSession) AddCallback(dataCallback DataCallback, errorCallback ErrCallback) *TCPSession

AddCallback 添加回调

func (*TCPSession) CloseRead

func (object *TCPSession) CloseRead()

关闭读

func (*TCPSession) CloseWrite

func (object *TCPSession) CloseWrite()

关闭写

func (*TCPSession) Connect

func (object *TCPSession) Connect(addr string) (err error)

Connect 连接

func (*TCPSession) IsStopped

func (object *TCPSession) IsStopped() bool

IsStopped 是否已停止

func (*TCPSession) NeedClose

func (object *TCPSession) NeedClose() bool

需要关闭

func (*TCPSession) SetConn

func (object *TCPSession) SetConn(c net.Conn) *TCPSession

SetConn 设置连接

func (*TCPSession) SetDebug

func (object *TCPSession) SetDebug() *TCPSession

设置调试标志

func (*TCPSession) SetMode

func (object *TCPSession) SetMode(mode TCPSessionMode) *TCPSession

设置模式

func (*TCPSession) SetName

func (object *TCPSession) SetName(name string) *TCPSession

设置名称

func (*TCPSession) Start

func (object *TCPSession) Start()

Start 启动

func (*TCPSession) Stop

func (object *TCPSession) Stop()

Stop 停止

func (*TCPSession) Write

func (object *TCPSession) Write(raw []byte)

Write 写

type TCPSessionMode

type TCPSessionMode int

TCP会话模式

type TCPSessionPool

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

TCPSessionPool TCP会话池

func GetTCPSessionPoolInstance

func GetTCPSessionPoolInstance() *TCPSessionPool

GetTCPSessionPoolInstance 获取单实例

func (*TCPSessionPool) Borrow

func (object *TCPSessionPool) Borrow() *TCPSession

Borrow 获取TCP会话

func (*TCPSessionPool) Return

func (object *TCPSessionPool) Return(tcpSession *TCPSession)

Return 退还TCP会话

Jump to

Keyboard shortcuts

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