socket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// Session 对应客户端连接
	Session *Session
	// MsgType 消息类型
	MsgType message.Type
	// Payload 消息体
	Payload interface{}
	// contains filtered or unexported fields
}

Context 上下文信息

func (*Context) Abort

func (ctx *Context) Abort()

Abort 中断执行

func (*Context) IsAborted

func (ctx *Context) IsAborted() bool

IsAborted 是否中断

func (*Context) Next

func (ctx *Context) Next()

Next 执行下一个中间件

type Handler

type Handler func(ctx *Context)

Handler 路由处理器

type HandlersChain

type HandlersChain []Handler

HandlersChain 路由处理器链

type Hub

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

Hub session管理

func NewHub

func NewHub(broadcastQueueSize int) *Hub

NewHub 创建session集合实例

func (*Hub) Add

func (ch *Hub) Add(sessionID string, w io.Writer)

Add 添加session

func (*Hub) Broadcast

func (ch *Hub) Broadcast(data []byte)

Broadcast 广播

func (*Hub) Delete

func (ch *Hub) Delete(sessionID string)

Delete 删除session

func (*Hub) Get

func (ch *Hub) Get(sessionID string) (io.Writer, bool)

Get 获取session

func (*Hub) Num

func (ch *Hub) Num() int32

Num session数量

func (*Hub) Range

func (ch *Hub) Range(f func(key, value interface{}) bool)

Range 遍历session

type Router

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

router 路由

func NewRouter

func NewRouter() *Router

NewRouter 创建实例

func (*Router) Dispatch

func (r *Router) Dispatch(session *Session, codec codec.Codec, data []byte)

Dispatch 路由分发

func (*Router) ErrorHandler

func (r *Router) ErrorHandler(h func(session *Session, err interface{}))

ErrorHandler 错误处理

func (*Router) NotFoundHandler

func (r *Router) NotFoundHandler(h func(session *Session, codec codec.Codec, data []byte))

NotFoundHandler 未找到handler

func (*Router) Register

func (r *Router) Register(msgType message.Type, payload interface{}, handler Handler) *Router

Register 路由注册

func (*Router) Use

func (r *Router) Use(middleware ...Handler)

Use 设置全局中间件

type Session

type Session struct {
	ID string
	// Data 保存Session相关数据
	Data sync.Map
	// contains filtered or unexported fields
}

Session 对应一个客户端连接

func NewSession

func NewSession(conn conn.Conn, handler SessionHandler, opt ...SessionOption) *Session

NewSession 创建session实例

func (*Session) Close

func (s *Session) Close()

Close 关闭连接

func (*Session) CloseNotify

func (s *Session) CloseNotify() <-chan struct{}

CloseNotify 连接关闭通知

func (*Session) Closed

func (s *Session) Closed() bool

Closed 连接是否已关闭

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

RemoteAddr 远程主机地址

func (*Session) Run

func (s *Session) Run()

Run 运行

func (*Session) Write

func (s *Session) Write(data []byte) (n int, err error)

Write 写入数据

type SessionHandler

type SessionHandler interface {
	OnConnect(*Session)
	OnMessage(*Session, []byte)
	OnClose(*Session)
	OnError(*Session, error)
}

SessionHandler 事件处理

type SessionOption

type SessionOption func(*options)

SessionOption 可选项

func WithSessionHeartBeatTimeout

func WithSessionHeartBeatTimeout(d time.Duration) SessionOption

WithSessionHeartBeatTimeout 心跳超时

func WithSessionHeartBeatTimeoutTimes

func WithSessionHeartBeatTimeoutTimes(times int) SessionOption

WithSessionHeartBeatTimeoutTimes 心跳超时次数

func WithSessionReadLimit

func WithSessionReadLimit(limit int64) SessionOption

WithSessionReadLimit 读取最大字节数

func WithSessionReadTimeout

func WithSessionReadTimeout(d time.Duration) SessionOption

WithSessionReadTimeout 读取超时

func WithSessionReceiveQueueSize

func WithSessionReceiveQueueSize(size int) SessionOption

WithSessionReceiveQueueSize 接收队列大小

func WithSessionSendQueueSize

func WithSessionSendQueueSize(size int) SessionOption

WithSessionSendQueueSize 发送队列大小

func WithSessionWriteTimeout

func WithSessionWriteTimeout(d time.Duration) SessionOption

WithSessionWriteTimeout 写入超时

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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