Documentation ¶
Overview ¶
Package session for knetty
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloseCallBackFunc ¶
type CloseCallBackFunc func(Session)
CloseCallBackFunc exec when session stopping
type Codec ¶
type Codec interface { // Encode will convert object to binary network data Encode(pkg interface{}) ([]byte, error) // Decode will convert binary network data into upper-layer protocol objects. // The following three conditions are used to distinguish abnormal, half - wrapped, normal and sticky packets. // Exceptions: nil,0,err // Half-pack: nil,0,nil // Normal & Sticky package: pkg,pkgLen,nil Decode([]byte) (interface{}, int, error) }
Codec for session
type EventListener ¶
type EventListener interface { // OnConnect runs when the connection initialized OnConnect(s Session) // OnMessage runs when the session gets a pkg OnMessage(s Session, pkg interface{}) ExecStatus // OnError runs when the session err OnError(s Session, e error) // OnClose runs before the session closed OnClose(s Session) }
EventListener listener for session event
type Session ¶
type Session interface { // LocalAddr return local address (for example, "192.0.2.1:25", "[2001:db8::1]:80") LocalAddr() string // RemoteAddr return remote address (for example, "192.0.2.1:25", "[2001:db8::1]:80") RemoteAddr() string // SetCodec setting yourself codec is necessary, otherwise a panic will occur at runtime SetCodec(Codec) // SetEventListener setting yourself eventListener is necessary, otherwise a panic will occur at runtime SetEventListener(EventListener) // WritePkg will encode any type of data as a []byte type using the codec and writes it to the conn buffer. // If you want the other end of the network to receive it, // call the FlushBuffer API to send all the data from the conn buffer out WritePkg(pkg interface{}) (int, error) // WriteBuffer will write bytes to conn buffer WriteBuffer(bytes []byte) (int, error) // FlushBuffer will send conn buffer data to net FlushBuffer() error // Run will run this session Run() error // SetCloseCallBackFunc setting closeBackFunc for session SetCloseCallBackFunc(fn CloseCallBackFunc) // Info return session info Info() string // Close will stop session Close() error }
Session client、server session
func NewSession ¶
func NewSession(conn connection.Connection) Session
NewSession create new session.
type WrappedEventTrigger ¶ added in v0.2.0
type WrappedEventTrigger struct {
// contains filtered or unexported fields
}
func NewSessionEventTrigger ¶ added in v0.2.0
func NewSessionEventTrigger(session *session) *WrappedEventTrigger
func (WrappedEventTrigger) OnConnHup ¶ added in v0.2.0
func (s WrappedEventTrigger) OnConnHup()
func (WrappedEventTrigger) OnConnReadable ¶ added in v0.2.0
func (s WrappedEventTrigger) OnConnReadable(buf []byte) int
Click to show internal directories.
Click to hide internal directories.