network

package
v0.0.0-...-1905027 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Default_ReadDeadline    = time.Second * 30 //默认读超时30s
	Default_WriteDeadline   = time.Second * 30 //默认写超时30s
	Default_MaxConnNum      = 1000000          //默认最大连接数
	Default_PendingWriteNum = 100000           //单连接写消息Channel容量
	Default_LittleEndian    = false            //默认大小端
	Default_MinMsgLen       = 2                //最小消息长度2byte
	Default_LenMsgLen       = 2                //包头字段长度占用2byte
	Default_MaxMsgLen       = 65535            //最大消息长度
)

Variables

View Source
var DefaultMaxHeaderBytes int = 1 << 20

Functions

func NewMemAreaPool

func NewMemAreaPool() *memAreaPool

Types

type Agent

type Agent interface {
	Run()
	OnClose()
}

type CAFile

type CAFile struct {
	CertFile string
	Keyfile  string
}

type Conn

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

type ConnSet

type ConnSet map[net.Conn]struct{}

type HttpServer

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

func (*HttpServer) Init

func (slf *HttpServer) Init(listenAddr string, handler http.Handler, readTimeout time.Duration, writeTimeout time.Duration)

func (*HttpServer) SetCAFile

func (slf *HttpServer) SetCAFile(caFile []CAFile)

func (*HttpServer) Start

func (slf *HttpServer) Start()

type INetMempool

type INetMempool interface {
	MakeByteSlice(size int) []byte
	ReleaseByteSlice(byteBuff []byte) bool
}

type MsgParser

type MsgParser struct {
	LenMsgLen    int
	MinMsgLen    uint32
	MaxMsgLen    uint32
	LittleEndian bool

	INetMempool
}

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

func (*MsgParser) Read

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

goroutine safe

func (*MsgParser) Write

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

goroutine safe

type TCPClient

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

	// msg parser
	MsgParser
	// contains filtered or unexported fields
}

func (*TCPClient) Close

func (client *TCPClient) Close(waitDone bool)

func (*TCPClient) GetCloseFlag

func (client *TCPClient) GetCloseFlag() bool

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

func (tcpConn *TCPConn) Destroy()

func (*TCPConn) GetRemoteIp

func (tcpConn *TCPConn) GetRemoteIp() string

func (*TCPConn) IsConnected

func (tcpConn *TCPConn) IsConnected() bool

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

func (*TCPConn) ReleaseReadMsg

func (tcpConn *TCPConn) ReleaseReadMsg(byteBuff []byte)

func (*TCPConn) RemoteAddr

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

func (*TCPConn) SetReadDeadline

func (tcpConn *TCPConn) SetReadDeadline(d time.Duration)

func (*TCPConn) SetWriteDeadline

func (tcpConn *TCPConn) SetWriteDeadline(d time.Duration)

func (*TCPConn) Write

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

b must not be modified by the others goroutines

func (*TCPConn) WriteMsg

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

func (*TCPConn) WriteRawMsg

func (tcpConn *TCPConn) WriteRawMsg(args []byte) error

type TCPServer

type TCPServer struct {
	Addr            string
	MaxConnNum      int
	PendingWriteNum int
	ReadDeadline    time.Duration
	WriteDeadline   time.Duration

	NewAgent func(*TCPConn) Agent

	MsgParser
	// contains filtered or unexported fields
}

func (*TCPServer) Close

func (server *TCPServer) Close()

func (*TCPServer) GetNetMempool

func (server *TCPServer) GetNetMempool() INetMempool

func (*TCPServer) SetNetMempool

func (server *TCPServer) SetNetMempool(mempool INetMempool)

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
	MessageType      int
	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) Destroy

func (wsConn *WSConn) Destroy()

func (*WSConn) LocalAddr

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

func (*WSConn) ReadMsg

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

goroutine not safe

func (*WSConn) RemoteAddr

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

func (*WSConn) WriteMsg

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

args must not be modified by the others goroutines

type WSHandler

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

func (*WSHandler) ServeHTTP

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

func (*WSHandler) SetMessageType

func (handler *WSHandler) SetMessageType(messageType int)

type WSServer

type WSServer struct {
	Addr            string
	MaxConnNum      int
	PendingWriteNum 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) SetMessageType

func (server *WSServer) SetMessageType(messageType int)

func (*WSServer) Start

func (server *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