network

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: MIT Imports: 12 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 {
	Read(buffer []byte) (int, error)
	ReadMsg(buf *bytes.Buffer) error
	WriteMessage(buf []byte) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close()
}

type ConnSet

type ConnSet map[net.Conn]struct{}

type MsgParser

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

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

func NewMsgParser

func NewMsgParser() *MsgParser

func (*MsgParser) Read

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

goroutine safe

func (*MsgParser) SetByteOrder

func (p *MsgParser) SetByteOrder(littleEndian bool)

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

func (*MsgParser) SetMsgLen

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

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

func (*MsgParser) Write

func (p *MsgParser) Write(conn *TCPConn, respId uint32, data []byte) error

goroutine safe

type TCPClient

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

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

func (*TCPClient) Close

func (client *TCPClient) Close()

func (*TCPClient) Start

func (client *TCPClient) Start()

type TCPConn

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

func (*TCPConn) Close

func (tcpConn *TCPConn) Close()

func (*TCPConn) LocalAddr

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

func (*TCPConn) Read

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

Read buffer length data

func (*TCPConn) ReadMsg

func (tcpConn *TCPConn) ReadMsg(buf *bytes.Buffer) error

func (*TCPConn) RemoteAddr

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

func (*TCPConn) WriteMessage

func (tcpConn *TCPConn) WriteMessage(buf []byte) error

type TCPServer

type TCPServer struct {
	Addr       string
	MaxConnNum int
	NewAgent   func(*TCPConn) Agent
	// contains filtered or unexported fields
}

func (*TCPServer) Close

func (server *TCPServer) Close()

func (*TCPServer) Start

func (server *TCPServer) Start()

type WSClient

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

func (client *WSClient) Close()

func (*WSClient) Start

func (client *WSClient) Start()

type WSConn

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

func (*WSConn) Close

func (wsConn *WSConn) Close()

func (*WSConn) LocalAddr

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

func (*WSConn) Read

func (wsConn *WSConn) Read(buffer []byte) (int, error)

func (*WSConn) ReadMsg

func (wsConn *WSConn) ReadMsg(buf *bytes.Buffer) error

goroutine not safe

func (*WSConn) RemoteAddr

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

func (*WSConn) WriteMessage

func (wsConn *WSConn) WriteMessage(buf []byte) error

type WSHandler

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

func (*WSHandler) ServeHTTP

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

type WSServer

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

func (*WSServer) Close

func (server *WSServer) Close()

func (*WSServer) Start

func (server *WSServer) Start()

type WebsocketConnSet

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

Jump to

Keyboard shortcuts

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