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 Channel
- type Config
- type ConnType
- type Connection
- func (r *Connection) Close() error
- func (r *Connection) Conn() (net.Conn, ConnType)
- func (r *Connection) DieChan() chan struct{}
- func (r *Connection) ID() int64
- func (r *Connection) LastMID() uint64
- func (r *Connection) Send(header, payload interface{}) (err error)
- func (r *Connection) SendBytes(data []byte) (err error)
- func (r *Connection) Serve()
- func (r *Connection) Session() *session.Session
- func (r *Connection) SetLastMID(mid uint64)
- func (r *Connection) SetStatus(s int32)
- func (r *Connection) Status() int32
- type Func
- 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 Manager
- func (m *Manager) FindConn(id int64) (*Connection, bool)
- func (m *Manager) FindConnByUID(uid string) (*Connection, bool)
- func (m *Manager) FindGroup(name string) (*Group, bool)
- func (m *Manager) NewGroup(name string) *Group
- func (m *Manager) PeekConn(fn func(id int64, c *Connection) bool)
- func (m *Manager) Remove(c *Connection) error
- func (m *Manager) RemoveFromGroup(groupName string, c *Connection) error
- func (m *Manager) Store(groupName string, c *Connection) error
- type PendingMessage
- type Pipeline
- 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") )
Functions ¶
func NewSerialAddr ¶ added in v1.0.0
Types ¶
type Channel ¶
type Channel interface { PushFront(h Func) PushBack(h Func) Process(c *Connection, v interface{}) error }
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection( id int64, conn net.Conn, pool *ants.Pool, conf Config, packerBuilder packet.PackerBuilder, serializer ndef.Serializer, pipeline Pipeline, handleFn packetFn) *Connection
func (*Connection) Close ¶
func (r *Connection) Close() error
func (*Connection) DieChan ¶
func (r *Connection) DieChan() chan struct{}
func (*Connection) ID ¶
func (r *Connection) ID() int64
func (*Connection) LastMID ¶
func (r *Connection) LastMID() uint64
func (*Connection) Send ¶
func (r *Connection) Send(header, payload interface{}) (err error)
func (*Connection) SendBytes ¶
func (r *Connection) SendBytes(data []byte) (err error)
func (*Connection) Serve ¶
func (r *Connection) Serve()
func (*Connection) Session ¶
func (r *Connection) Session() *session.Session
func (*Connection) SetLastMID ¶
func (r *Connection) SetLastMID(mid uint64)
func (*Connection) SetStatus ¶
func (r *Connection) SetStatus(s int32)
func (*Connection) Status ¶
func (r *Connection) Status() int32
type Func ¶
type Func func(c *Connection, v interface{}) error
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 Manager ¶
func NewManager ¶
func NewManager() *Manager
func (*Manager) FindConn ¶
func (m *Manager) FindConn(id int64) (*Connection, bool)
FindConn 根据连接ID找到连接
func (*Manager) FindConnByUID ¶
func (m *Manager) FindConnByUID(uid string) (*Connection, bool)
FindConnByUID 根据连接绑定的UID找到连接
func (*Manager) PeekConn ¶
func (m *Manager) PeekConn(fn func(id int64, c *Connection) bool)
PeekConn 循环所有连接 fn 返回true跳过循环,反之一直循环
func (*Manager) Remove ¶
func (m *Manager) Remove(c *Connection) error
func (*Manager) RemoveFromGroup ¶
func (m *Manager) RemoveFromGroup(groupName string, c *Connection) error
type PendingMessage ¶
type PendingMessage struct {
// contains filtered or unexported fields
}
type SerialAddr ¶ added in v1.0.0
func (*SerialAddr) Network ¶ added in v1.0.0
func (r *SerialAddr) Network() string
func (*SerialAddr) String ¶ added in v1.0.0
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.0.0
SerialConn serial connection wrapper
func (*SerialConn) LocalAddr ¶ added in v1.0.0
func (c *SerialConn) LocalAddr() net.Addr
func (*SerialConn) RemoteAddr ¶ added in v1.0.0
func (c *SerialConn) RemoteAddr() net.Addr
func (*SerialConn) SetDeadline ¶ added in v1.0.0
func (c *SerialConn) SetDeadline(_ time.Time) error
func (*SerialConn) SetReadDeadline ¶ added in v1.0.0
func (c *SerialConn) SetReadDeadline(_ time.Time) error
func (*SerialConn) SetWriteDeadline ¶ added in v1.0.0
func (c *SerialConn) SetWriteDeadline(_ time.Time) error
type WSConn ¶
WSConn 封装 websocket.Conn 并实现所有 net.Conn 接口 兼容所有使用 net.Conn 的方法
func (*WSConn) Read ¶
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 ¶
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.