Documentation
¶
Index ¶
- type Kind
- type Session
- func (s *Session) AddConn(conn network.Conn)
- func (s *Session) Bind(cid, uid int64) error
- func (s *Session) Broadcast(kind Kind, disconnect bool, buf buffer.Buffer) (int64, error)
- func (s *Session) Close(kind Kind, target int64, force ...bool) error
- func (s *Session) Has(kind Kind, target int64) (ok bool, err error)
- func (s *Session) LocalAddr(kind Kind, target int64) (net.Addr, error)
- func (s *Session) LocalIP(kind Kind, target int64) (string, error)
- func (s *Session) Multicast(kind Kind, targets []int64, disconnect bool, buf buffer.Buffer) (int64, error)
- func (s *Session) Publish(channel string, disconnect bool, buf buffer.Buffer) (int64, error)
- func (s *Session) Push(kind Kind, target int64, disconnect bool, buf buffer.Buffer) error
- func (s *Session) RemConn(conn network.Conn) bool
- func (s *Session) RemoteAddr(kind Kind, target int64) (net.Addr, error)
- func (s *Session) RemoteIP(kind Kind, target int64) (string, error)
- func (s *Session) Stat(kind Kind) (int64, error)
- func (s *Session) Subscribe(kind Kind, targets []int64, channel string) (err error)
- func (s *Session) Unbind(uid int64) (int64, error)
- func (s *Session) Unsubscribe(kind Kind, targets []int64, channel string) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session manages the connection and user sessions of a node along with their channel subscriptions.
func (*Session) Bind ¶
Bind binds the user ID uid to the connection identified by cid. When uid is already bound to another connection, that connection is closed and replaced.
func (*Session) Broadcast ¶
Broadcast pushes buf to every session of the given kind asynchronously. When disconnect is true, each connection is closed after the push. It returns the number of sessions the message was pushed to, or errors.ErrInvalidSessionKind for an unknown kind.
func (*Session) Close ¶
Close closes the session identified by target. The kind selects whether target is a connection ID or a user ID. Pass force as true to close the connection forcibly.
func (*Session) Has ¶
Has reports whether the session identified by target exists. The kind selects whether target is a connection ID or a user ID. It reports errors.ErrInvalidSessionKind for an unknown kind.
func (*Session) LocalAddr ¶
LocalAddr returns the local address of the session identified by target. The kind selects whether target is a connection ID or a user ID.
func (*Session) LocalIP ¶
LocalIP returns the local IP address of the session identified by target. The kind selects whether target is a connection ID or a user ID.
func (*Session) Multicast ¶
func (s *Session) Multicast(kind Kind, targets []int64, disconnect bool, buf buffer.Buffer) (int64, error)
Multicast pushes buf to every session in targets asynchronously. The kind selects whether each target is a connection ID or a user ID. When disconnect is true, each connection is closed after the push. It returns the number of sessions the message was pushed to, or errors.ErrInvalidSessionKind for an unknown kind.
func (*Session) Publish ¶ added in v2.3.0
Publish pushes buf to every session subscribed to channel asynchronously. When disconnect is true, each connection is closed after the push. It returns the number of sessions the message was pushed to.
func (*Session) Push ¶
Push pushes buf to the session identified by target asynchronously. The kind selects whether target is a connection ID or a user ID. When disconnect is true, the connection is closed after the push.
func (*Session) RemConn ¶
RemConn removes conn from the connection sessions. It reports whether conn was registered and has been removed.
The existence check and the removal happen under the same write lock, so the caller does not need to call Session.Has before RemConn and pay for a second lookup. When the same conn is removed concurrently, only the first call reports true, which keeps repeated removals from unbalancing the counters.
func (*Session) RemoteAddr ¶
RemoteAddr returns the remote address of the session identified by target. The kind selects whether target is a connection ID or a user ID.
func (*Session) RemoteIP ¶
RemoteIP returns the remote IP address of the session identified by target. The kind selects whether target is a connection ID or a user ID.
func (*Session) Stat ¶
Stat returns the number of sessions of the given kind, or errors.ErrInvalidSessionKind for an unknown kind.
func (*Session) Subscribe ¶ added in v2.3.0
Subscribe subscribes the sessions in targets to channel. The kind selects whether each target is a connection ID or a user ID. It reports errors.ErrInvalidSessionKind for an unknown kind.
func (*Session) Unbind ¶
Unbind unbinds the user ID uid and returns the ID of the connection it was bound to.
func (*Session) Unsubscribe ¶ added in v2.3.0
Unsubscribe unsubscribes the sessions in targets from channel. The kind selects whether each target is a connection ID or a user ID. It reports errors.ErrInvalidSessionKind for an unknown kind.