tcp

package
v5.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READCHAN_SIZE  = 1024
	WRITECHAN_SIZE = 0
)

Variables

View Source
var (
	ErrSessionClosing = errors.New("use of closed network connection")
	ErrBufferFull     = errors.New("the async buffer is full")
)

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Handle(sess *Session, data []byte)
	MakeSession(sess *Session)
	LostSession(sess *Session)
}

type Server

type Server struct {
	Addr    string //TCP address to listen on
	Listen  *net.TCPListener
	Handler Handler

	Sessions SessionBucket
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string, handler Handler) *Server

func (*Server) Connect

func (srv *Server) Connect(addr string, handler Handler) (*Session, error)

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener)

func (*Server) SetMaxPacketSize

func (srv *Server) SetMaxPacketSize(size uint32)

在ListenAndServe之前调用

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) Close

func (sess *Session) Close()

func (*Session) IsClosed

func (sess *Session) IsClosed() bool

func (*Session) LocalAddr

func (sess *Session) LocalAddr() string

func (*Session) RemoteAddr

func (sess *Session) RemoteAddr() string

func (*Session) RemoteIPAddr

func (sess *Session) RemoteIPAddr() string

func (*Session) Send

func (sess *Session) Send(data []byte) error

func (*Session) Serve

func (sess *Session) Serve()

type SessionBucket

type SessionBucket struct {
	// contains filtered or unexported fields
}

func (*SessionBucket) Add

func (sb *SessionBucket) Add(sess *Session)

func (*SessionBucket) All

func (sb *SessionBucket) All() map[string]*Session

func (*SessionBucket) Delete

func (sb *SessionBucket) Delete(ip string)

func (*SessionBucket) Get

func (sb *SessionBucket) Get(ip string) *Session

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL