Documentation ¶
Index ¶
- Constants
- Variables
- func NewSerialAddr(addr string, rate int, dataBits int, stopBits int, parity string) net.Addr
- func NewSerialConn(port serial.Port, cfg *serial.Config) net.Conn
- type ConnManager
- func (m *ConnManager) FindConn(id int64) (*Connection, bool)
- func (m *ConnManager) FindConnByUID(uid string) (*Connection, bool)
- func (m *ConnManager) FindGroup(name string) (*Group, bool)
- func (m *ConnManager) NewGroup(name string) *Group
- func (m *ConnManager) PeekConn(fn func(id int64, c *Connection) bool)
- func (m *ConnManager) Remove(c *Connection) error
- func (m *ConnManager) RemoveFromGroup(groupName string, c *Connection) error
- func (m *ConnManager) Store(groupName string, c *Connection) error
- type ConnType
- type Connection
- func (r *Connection) ChDie() chan struct{}
- func (r *Connection) ChSend() chan PendingMessage
- func (r *Connection) ChWrite() chan []byte
- func (r *Connection) Close() error
- func (r *Connection) Conn() net.Conn
- func (r *Connection) ID() int64
- func (r *Connection) LastMID() uint64
- func (r *Connection) Send(header, payload any) (err error)
- func (r *Connection) SendBytes(data []byte) (err error)
- func (r *Connection) SerialConn() *SerialConn
- func (r *Connection) Session() *session.Session
- func (r *Connection) SetLastMID(mid uint64)
- func (r *Connection) SetStatus(s int32)
- func (r *Connection) Status() int32
- func (r *Connection) Type() ConnType
- func (r *Connection) WsConn() *WSConn
- type Group
- func (g *Group) Add(c *Connection) error
- func (g *Group) Close() error
- func (g *Group) Contains(uid string) bool
- func (g *Group) Count() int
- func (g *Group) Leave(c *Connection) error
- func (g *Group) LeaveAll() error
- func (g *Group) LeaveByUID(uid string) error
- func (g *Group) Member(uid string) (*Connection, bool)
- func (g *Group) MemberBySID(id int64) (*Connection, bool)
- func (g *Group) Members() []*Connection
- func (g *Group) PeekMembers(fn func(sId int64, c *Connection) bool)
- type PendingMessage
- type SerialAddr
- type SerialConn
- type WSConn
Constants ¶
const ( // StatusStart 开始阶段 StatusStart int32 = iota + 1 // StatusPrepare 准备阶段 StatusPrepare // StatusPending 等待工作阶段 StatusPending // StatusWorking 工作阶段 StatusWorking // StatusClosed 连接关闭 StatusClosed )
const DefaultGroupName = "DEFAULT_GROUP"
const SerialNetwork = "serial"
Variables ¶
var ( ErrCloseClosedSession = errors.New("close closed session") // ErrBrokenPipe represents the low-level connection has broken. ErrBrokenPipe = errors.New("broken low-level pipe") ErrSendPayload = errors.New("serializer is nil, but payload type not []byte") ErrSendMarshal = errors.New("message body marshal err") ErrSend = errors.New("send err") ErrSendWSType = errors.New("websocket message type err") ErrPack = errors.New("pack err") ErrUnpack = errors.New("unPacker err") ErrNoPacker = errors.New("no packer") ErrReceiveZero = errors.New("receive zero") )
Functions ¶
func NewSerialAddr ¶ added in v1.1.4
Types ¶
type ConnManager ¶
func NewConnManager ¶ added in v1.1.4
func NewConnManager() *ConnManager
func (*ConnManager) FindConn ¶ added in v1.1.4
func (m *ConnManager) FindConn(id int64) (*Connection, bool)
FindConn 根据连接ID找到连接
func (*ConnManager) FindConnByUID ¶ added in v1.1.4
func (m *ConnManager) FindConnByUID(uid string) (*Connection, bool)
FindConnByUID 根据连接绑定的UID找到连接
func (*ConnManager) FindGroup ¶ added in v1.1.4
func (m *ConnManager) FindGroup(name string) (*Group, bool)
FindGroup 查找分组
func (*ConnManager) NewGroup ¶ added in v1.1.4
func (m *ConnManager) NewGroup(name string) *Group
NewGroup 新增分组,若分组已存在,则返回现有分组
func (*ConnManager) PeekConn ¶ added in v1.1.4
func (m *ConnManager) PeekConn(fn func(id int64, c *Connection) bool)
PeekConn 循环所有连接 fn 返回true跳过循环,反之一直循环
func (*ConnManager) Remove ¶ added in v1.1.4
func (m *ConnManager) Remove(c *Connection) error
func (*ConnManager) RemoveFromGroup ¶ added in v1.1.4
func (m *ConnManager) RemoveFromGroup(groupName string, c *Connection) error
func (*ConnManager) Store ¶ added in v1.1.4
func (m *ConnManager) Store(groupName string, c *Connection) error
Store 保存连接,同时加入到指定分组,若给定分组名为空,则不进行分组操作
type Connection ¶ added in v1.1.4
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶ added in v1.1.4
func NewConnection(id int64, rawC net.Conn, sendSize, writeSize int) *Connection
func (*Connection) ChDie ¶ added in v1.1.4
func (r *Connection) ChDie() chan struct{}
func (*Connection) ChSend ¶ added in v1.1.4
func (r *Connection) ChSend() chan PendingMessage
func (*Connection) ChWrite ¶ added in v1.1.4
func (r *Connection) ChWrite() chan []byte
func (*Connection) Close ¶ added in v1.1.4
func (r *Connection) Close() error
func (*Connection) Conn ¶ added in v1.1.4
func (r *Connection) Conn() net.Conn
func (*Connection) ID ¶ added in v1.1.4
func (r *Connection) ID() int64
func (*Connection) LastMID ¶ added in v1.1.4
func (r *Connection) LastMID() uint64
func (*Connection) Send ¶ added in v1.1.4
func (r *Connection) Send(header, payload any) (err error)
func (*Connection) SendBytes ¶ added in v1.1.4
func (r *Connection) SendBytes(data []byte) (err error)
func (*Connection) SerialConn ¶ added in v1.1.4
func (r *Connection) SerialConn() *SerialConn
func (*Connection) Session ¶ added in v1.1.4
func (r *Connection) Session() *session.Session
func (*Connection) SetLastMID ¶ added in v1.1.4
func (r *Connection) SetLastMID(mid uint64)
func (*Connection) SetStatus ¶ added in v1.1.4
func (r *Connection) SetStatus(s int32)
func (*Connection) Status ¶ added in v1.1.4
func (r *Connection) Status() int32
func (*Connection) Type ¶ added in v1.1.4
func (r *Connection) Type() ConnType
func (*Connection) WsConn ¶ added in v1.1.4
func (r *Connection) WsConn() *WSConn
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) Leave ¶
func (g *Group) Leave(c *Connection) error
Leave remove specified UID related session from group
func (*Group) LeaveByUID ¶
func (*Group) Member ¶
func (g *Group) Member(uid string) (*Connection, bool)
Member returns connection by specified uid
func (*Group) MemberBySID ¶
func (g *Group) MemberBySID(id int64) (*Connection, bool)
MemberBySID returns specified sId's connection
func (*Group) Members ¶
func (g *Group) Members() []*Connection
func (*Group) PeekMembers ¶
func (g *Group) PeekMembers(fn func(sId int64, c *Connection) bool)
PeekMembers returns all members in current group fn 返回true跳过循环,反之一直循环
type PendingMessage ¶ added in v1.1.4
type SerialAddr ¶ added in v1.1.4
func (*SerialAddr) Network ¶ added in v1.1.4
func (r *SerialAddr) Network() string
func (*SerialAddr) String ¶ added in v1.1.4
func (r *SerialAddr) String() string
String form of address (for example, "/dev/ttyS0|19200|8|1|N", "com1|19200|8|1|N")
type SerialConn ¶ added in v1.1.4
SerialConn serial connection wrapper
func (*SerialConn) LocalAddr ¶ added in v1.1.4
func (c *SerialConn) LocalAddr() net.Addr
func (*SerialConn) RemoteAddr ¶ added in v1.1.4
func (c *SerialConn) RemoteAddr() net.Addr
func (*SerialConn) SetDeadline ¶ added in v1.1.4
func (c *SerialConn) SetDeadline(_ time.Time) error
func (*SerialConn) SetReadDeadline ¶ added in v1.1.4
func (c *SerialConn) SetReadDeadline(_ time.Time) error
func (*SerialConn) SetWriteDeadline ¶ added in v1.1.4
func (c *SerialConn) SetWriteDeadline(_ time.Time) error
type WSConn ¶ added in v1.1.4
WSConn 封装 websocket.Conn 并实现所有 net.Conn 接口 兼容所有使用 net.Conn 的方法
func (*WSConn) Read ¶ added in v1.1.4
Read reads data from the connection. Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*WSConn) SetDeadline ¶ added in v1.1.4
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.
A zero value for t means I/O operations will not time out.