Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type EventListener
- type NewSessionCallback
- type ReadWriter
- type Reader
- type Server
- func (this *Server) Accept(newSession NewSessionCallback) (*Session, error)
- func (this *Server) Bind(network string, host string, port int) error
- func (this *Server) Close()
- func (this *Server) IsClosed() bool
- func (this *Server) Listen(network string, addr string) error
- func (this *Server) Listener() net.Listener
- func (this *Server) RunEventloop(newSession NewSessionCallback)
- type Session
- func (this *Session) Close()
- func (this *Session) Conn() net.Conn
- func (this *Session) GetAttribute(key string) interface{}
- func (this *Session) IsClosed() bool
- func (this *Session) RemoveAttribute(key string)
- func (this *Session) Reset()
- func (this *Session) RunEventLoop()
- func (this *Session) SetAttribute(key string, value interface{})
- func (this *Session) SetConn(conn net.Conn)
- func (this *Session) SetCronPeriod(period int)
- func (this *Session) SetEventListener(listener EventListener)
- func (this *Session) SetName(name string)
- func (this *Session) SetPkgHandler(handler ReadWriter)
- func (this *Session) SetRQLen(readQLen int)
- func (this *Session) SetReadDeadline(rDeadline time.Duration)
- func (this *Session) SetWQLen(writeQLen int)
- func (this *Session) SetWaitTime(waitTime time.Duration)
- func (this *Session) SetWriteDeadline(wDeadline time.Duration)
- func (this *Session) Stat() string
- func (this *Session) WriteBytes(pkg []byte) error
- func (this *Session) WritePkg(pkg interface{}) error
- type Writer
Constants ¶
const ( Version = "0.3.14" GETTY_MAJOR = 0 GETTY_MINOR = 3 GETTY_BUILD = 14 )
Variables ¶
var ( ErrSessionClosed = errors.New("Session Already Closed") ErrSessionBlocked = errors.New("Session full blocked") )
var (
ErrInvalidConnection = errors.New("connection has been closed.")
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
func NewClient ¶
NewClient function builds a client. @connNum is connection number. @connInterval is reconnect sleep interval when getty fails to connect the server. @serverAddr is server address.
func (*Client) RunEventLoop ¶
func (this *Client) RunEventLoop(newSession NewSessionCallback)
type EventListener ¶
type EventListener interface { // invoked when session opened // If the return error is not nil, @Session will be closed. OnOpen(*Session) error // invoked when session closed. when @Session got error, session will not invoke @OnClose but invoke @OnError. OnClose(*Session) // invoked when got error. OnError(*Session, error) // invoked periodically, its period can be set by (Session)SetCronPeriod OnCron(*Session) // invoked when receive packge. Pls attention that do not handle long time logic processing in this func. // Y'd better set the package's maximum length. If the message's length is greater than it, u should // should return err and getty will close this connection soon. OnMessage(*Session, interface{}) }
EventListener is used to process pkg that recved from remote session
type NewSessionCallback ¶
NewSessionCallback will be invoked when server accepts a new client connection or client connects to server successfully. if there are too many client connections or u do not want to connect a server again, u can return non-nil error. And then getty will close the new session.
type Reader ¶
type Reader interface { // Parse pkg from buffer and if possible return a complete pkg // If length of buf is not long enough, u should return {nil,0, nil} // The second return value is the length of the pkg. Read(*Session, []byte) (interface{}, int, error) }
Reader is used to unmarshal a complete pkg from buffer
type Server ¶
func (*Server) Listen ¶
net.ipv4.tcp_max_syn_backlog net.ipv4.tcp_timestamps net.ipv4.tcp_tw_recycle
func (*Server) RunEventloop ¶
func (this *Server) RunEventloop(newSession NewSessionCallback)
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
getty base session
func NewSession ¶
func (*Session) Close ¶
func (this *Session) Close()
this function will be invoked by NewSessionCallback(if return error is not nil) or (Session)handleLoop automatically. It is goroutine-safe to be invoked many times.
func (*Session) GetAttribute ¶
func (*Session) RemoveAttribute ¶
func (*Session) RunEventLoop ¶
func (this *Session) RunEventLoop()
func (*Session) SetAttribute ¶
func (*Session) SetCronPeriod ¶
period is in millisecond
func (*Session) SetEventListener ¶
func (this *Session) SetEventListener(listener EventListener)
func (*Session) SetPkgHandler ¶
func (this *Session) SetPkgHandler(handler ReadWriter)
set package handler
func (*Session) SetReadDeadline ¶
SetReadDeadline sets deadline for the future read calls.
func (*Session) SetWaitTime ¶
set maximum wait time when session got error or got exit signal
func (*Session) SetWriteDeadline ¶
SetWriteDeadlile sets deadline for the future read calls.