network

package
v0.0.0-...-33207d9 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 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 PkgParser

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

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

func NewPkgParser

func NewPkgParser() *PkgParser

func (*PkgParser) Read

func (p *PkgParser) Read(r io.Reader) ([]byte, error)

func (*PkgParser) SetEndian

func (p *PkgParser) SetEndian(isLittleEndian bool)

func (*PkgParser) SetPkgLen

func (p *PkgParser) SetPkgLen(byteLen int, minPkgLen, maxPkgLen uint32)

func (*PkgParser) Write

func (p *PkgParser) Write(w io.Writer, args ...[]byte) error

type Processor

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

type TCPClient struct {
	sync.Mutex
	Addr            string
	ConnNum         int
	ConnectInterval time.Duration // 连接失败后的重连时间间隔
	PendingWriteNum int           // 发送消息队列缓冲区长度
	AutoReconnect   bool
	NewAgent        func(conn *TCPConn) Agent

	// PkgParser
	ByteLen      int
	MinPkgLen    uint32
	MaxPkgLen    uint32
	LittleEndian bool
	// contains filtered or unexported fields
}

func (*TCPClient) Close

func (c *TCPClient) Close()

func (*TCPClient) Start

func (c *TCPClient) Start()

type TCPConn

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

func (*TCPConn) Close

func (c *TCPConn) Close()

Close 正常关闭,等待消息发送完成

func (*TCPConn) Destroy

func (c *TCPConn) Destroy()

func (*TCPConn) LocalAddr

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

func (*TCPConn) Read

func (c *TCPConn) Read(p []byte) (n int, err error)

func (*TCPConn) ReadMsg

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

func (*TCPConn) RemoteAddr

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

func (*TCPConn) Write

func (c *TCPConn) Write(p []byte) (n int, err error)

func (*TCPConn) WriteMsg

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

type TCPServer

type TCPServer struct {
	sync.Mutex
	Addr            string // 服务地址
	MaxConnNum      int    // 最大连接数
	PendingWriteNum int    // 消息发送队列缓冲区长度
	NewAgent        func(conn *TCPConn) Agent

	// PkgParser
	ByteLen      int
	MinPkgLen    uint32
	MaxPkgLen    uint32
	LittleEndian bool
	// contains filtered or unexported fields
}

func (*TCPServer) Close

func (s *TCPServer) Close()

func (*TCPServer) Start

func (s *TCPServer) Start()

type WSClient

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

func (*WSClient) Close

func (c *WSClient) Close()

func (*WSClient) Start

func (c *WSClient) Start()

type WSConn

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

func (*WSConn) Close

func (c *WSConn) Close()

func (*WSConn) Destroy

func (c *WSConn) Destroy()

func (*WSConn) LocalAddr

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

func (*WSConn) ReadMsg

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

func (*WSConn) RemoteAddr

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

func (*WSConn) WriteMsg

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

type WSHandler

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

func (*WSHandler) ServeHTTP

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

type WSServer

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

func (*WSServer) Close

func (s *WSServer) Close()

func (*WSServer) Start

func (s *WSServer) Start()

type WebsocketConnSet

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