network

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Recover

func Recover()

Types

type Agent

type Agent interface {
	OnInit()
	React([]byte)
	OnClose()
}

type Conn

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

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) Decode

func (p *MsgParser) Decode(c gnet.Conn) (data []byte, err error)

基于gnet接口的Decode

func (*MsgParser) Encode

func (p *MsgParser) Encode(c gnet.Conn, data []byte) ([]byte, error)

func (*MsgParser) Read

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

func (*MsgParser) SetByteOrder

func (p *MsgParser) SetByteOrder(littleEndian bool)

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

func (*MsgParser) SetLenMsgLenInMsg

func (p *MsgParser) SetLenMsgLenInMsg(lenMsgLenInMsg bool)

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, in []byte) error

goroutine safe

type Processor

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

type TCPClient

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

	// msg parser
	LenMsgLen      int
	MinMsgLen      uint32
	MaxMsgLen      uint32
	LittleEndian   bool
	LenMsgLenInMsg bool // if the msg len contain in "header" len

	Client_log bool
	ChanStop   bool
	// contains filtered or unexported fields
}

func (*TCPClient) Close

func (client *TCPClient) Close() error

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() error

func (*TCPConn) Destroy

func (tcpConn *TCPConn) Destroy()

func (*TCPConn) LocalAddr

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

func (*TCPConn) Read

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

func (*TCPConn) ReadMsg

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

func (*TCPConn) RemoteAddr

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

func (*TCPConn) Write

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

b must not be modified by the others goroutines

func (*TCPConn) WriteMsg

func (tcpConn *TCPConn) WriteMsg(msg []byte) error

type TCPServer

type TCPServer struct {
	Addr       string
	MaxConnNum int
	NewAgent   func(Conn) Agent

	// msg parser
	LenMsgLen      int
	MinMsgLen      uint32
	MaxMsgLen      uint32
	LittleEndian   bool
	LenMsgLenInMsg bool // if the msg len contain in "header" len

	ChanStop bool
	gnet.EventHandler
	Close func()
	// contains filtered or unexported fields
}

func (*TCPServer) OnClosed

func (server *TCPServer) OnClosed(c gnet.Conn, err error) (action gnet.Action)

func (*TCPServer) OnInitComplete

func (server *TCPServer) OnInitComplete(svr gnet.Server) gnet.Action

func (*TCPServer) OnOpened

func (server *TCPServer) OnOpened(c gnet.Conn) (out []byte, action gnet.Action)

func (*TCPServer) React

func (server *TCPServer) React(data []byte, c gnet.Conn) (action gnet.Action)

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() error

func (*WSConn) Destroy

func (wsConn *WSConn) Destroy()

func (*WSConn) LocalAddr

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

func (*WSConn) ReadMsg

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

goroutine not safe

func (*WSConn) RemoteAddr

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

func (*WSConn) WriteMsg

func (wsConn *WSConn) WriteMsg(msg []byte) error

args must not be modified by the others goroutines

type WSServer

type WSServer struct {
	Addr        string
	MaxConnNum  int
	MaxMsgLen   uint32
	CertFile    string
	KeyFile     string
	CaFile      string
	HTTPTimeout time.Duration
	NewAgent    func(Conn) Agent

	ConnNum int32
	gnet.EventHandler
	Close func()
	// contains filtered or unexported fields
}

func (*WSServer) OnClosed

func (server *WSServer) OnClosed(c gnet.Conn, err error) (action gnet.Action)

func (*WSServer) OnInitComplete

func (server *WSServer) OnInitComplete(svr gnet.Server) gnet.Action

func (*WSServer) OnOpened

func (server *WSServer) OnOpened(c gnet.Conn) (out []byte, action gnet.Action)

func (*WSServer) React

func (server *WSServer) React(data []byte, c gnet.Conn) (action gnet.Action)

func (*WSServer) Start

func (server *WSServer) Start()

Directories

Path Synopsis
dyb module

Jump to

Keyboard shortcuts

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