network

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	Run()
	OnClose()
}

type Conn

type Conn interface {
	ReadMsg() ([]byte, error)
	WriteMsg(args ...[]byte) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close()
	Destroy()
}

type ConnSet added in v1.0.4

type ConnSet map[net.Conn]struct{}

type MsgParser added in v1.0.4

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

-------------- | len | data | --------------

func NewMsgParser added in v1.0.4

func NewMsgParser() *MsgParser

func (*MsgParser) Read added in v1.0.4

func (p *MsgParser) Read(conn *TCPConn) ([]byte, error)

goroutine safe

func (*MsgParser) SetByteOrder added in v1.0.4

func (p *MsgParser) SetByteOrder(littleEndian bool)

It's dangerous to call the method on reading or writing

func (*MsgParser) SetMsgLen added in v1.0.4

func (p *MsgParser) SetMsgLen(lenMsgLen int, minMsgLen uint32, maxMsgLen uint32)

It's dangerous to call the method on reading or writing

func (*MsgParser) Write added in v1.0.4

func (p *MsgParser) Write(conn *TCPConn, args ...[]byte) error

goroutine safe

type Processor added in v1.0.4

type Processor interface {
	// must goroutine safe
	Route(msg interface{}, userData interface{}) error
	// must goroutine safe
	Unmarshal(data []byte) (interface{}, error)
	// must goroutine safe
	Marshal(msg interface{}) ([][]byte, error)
}

type TCPClient added in v1.0.4

type TCPClient struct {
	sync.Mutex
	Addr            string
	ConnNum         int
	ConnectInterval time.Duration
	PendingWriteNum int
	AutoReconnect   bool
	NewAgent        func(*TCPConn) Agent

	// msg parser
	LenMsgLen    int
	MinMsgLen    uint32
	MaxMsgLen    uint32
	LittleEndian bool
	// contains filtered or unexported fields
}

func (*TCPClient) Close added in v1.0.4

func (client *TCPClient) Close()

func (*TCPClient) Start added in v1.0.4

func (client *TCPClient) Start()

type TCPConn added in v1.0.4

type TCPConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*TCPConn) Close added in v1.0.4

func (tcpConn *TCPConn) Close()

func (*TCPConn) Destroy added in v1.0.4

func (tcpConn *TCPConn) Destroy()

func (*TCPConn) LocalAddr added in v1.0.4

func (tcpConn *TCPConn) LocalAddr() net.Addr

func (*TCPConn) Read added in v1.0.4

func (tcpConn *TCPConn) Read(b []byte) (int, error)

func (*TCPConn) ReadMsg added in v1.0.4

func (tcpConn *TCPConn) ReadMsg() ([]byte, error)

func (*TCPConn) RemoteAddr added in v1.0.4

func (tcpConn *TCPConn) RemoteAddr() net.Addr

func (*TCPConn) Write added in v1.0.4

func (tcpConn *TCPConn) Write(b []byte)

b must not be modified by the others goroutines

func (*TCPConn) WriteMsg added in v1.0.4

func (tcpConn *TCPConn) WriteMsg(args ...[]byte) error

type TCPServer added in v1.0.4

type TCPServer struct {
	Addr            string
	MaxConnNum      int
	PendingWriteNum int
	NewAgent        func(*TCPConn) Agent

	// msg parser
	LenMsgLen    int
	MinMsgLen    uint32
	MaxMsgLen    uint32
	LittleEndian bool
	// contains filtered or unexported fields
}

func (*TCPServer) Close added in v1.0.4

func (server *TCPServer) Close()

func (*TCPServer) Start added in v1.0.4

func (server *TCPServer) Start()

type WSClient added in v1.0.4

type WSClient struct {
	sync.Mutex
	Addr             string
	ConnNum          int
	ConnectInterval  time.Duration
	PendingWriteNum  int
	MaxMsgLen        uint32
	HandshakeTimeout time.Duration
	AutoReconnect    bool
	NewAgent         func(*WSConn) Agent
	// contains filtered or unexported fields
}

func (*WSClient) Close added in v1.0.4

func (client *WSClient) Close()

func (*WSClient) Start added in v1.0.4

func (client *WSClient) Start()

type WSConn added in v1.0.4

type WSConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*WSConn) Close added in v1.0.4

func (wsConn *WSConn) Close()

func (*WSConn) Destroy added in v1.0.4

func (wsConn *WSConn) Destroy()

func (*WSConn) LocalAddr added in v1.0.4

func (wsConn *WSConn) LocalAddr() net.Addr

func (*WSConn) ReadMsg added in v1.0.4

func (wsConn *WSConn) ReadMsg() ([]byte, error)

goroutine not safe

func (*WSConn) RemoteAddr added in v1.0.4

func (wsConn *WSConn) RemoteAddr() net.Addr

func (*WSConn) WriteMsg added in v1.0.4

func (wsConn *WSConn) WriteMsg(args ...[]byte) error

args must not be modified by the others goroutines

type WSHandler added in v1.0.4

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

func (*WSHandler) ServeHTTP added in v1.0.4

func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WSServer added in v1.0.4

type WSServer struct {
	Addr            string
	MaxConnNum      int
	PendingWriteNum int
	MaxMsgLen       uint32
	HTTPTimeout     time.Duration
	CertFile        string
	KeyFile         string
	NewAgent        func(*WSConn, *http.Request) Agent
	// contains filtered or unexported fields
}

func (*WSServer) Close added in v1.0.4

func (server *WSServer) Close()

func (*WSServer) Start added in v1.0.4

func (server *WSServer) Start()

type WebsocketConnSet added in v1.0.4

type WebsocketConnSet map[*websocket.Conn]struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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