tcp

package
v0.0.0-...-9c21ab8 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectlyWrite

func DirectlyWrite(conn *Conn, args ...[]byte) error

直接写入

Types

type Client

type Client struct {
	sync.Mutex
	Addr            string
	ConnNum         int
	ConnectInterval time.Duration
	PendingWriteNum int
	AutoReconnect   bool
	NewAgent        func(*Conn) network.Agent
	Parser          IParser
	// contains filtered or unexported fields
}

func NewClient

func NewClient(addr string, newAgentCallback func(*Conn) network.Agent, options ...Option) *Client

func (*Client) Close

func (client *Client) Close()

func (*Client) Start

func (client *Client) Start()

type Conn

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

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) Destroy

func (c *Conn) Destroy()

func (*Conn) LocalAddr

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

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) ReadMsg

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

func (*Conn) RemoteAddr

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

func (*Conn) Write

func (c *Conn) Write(b []byte)

b must not be modified by the others goroutines

func (*Conn) WriteMsg

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

type ConnSet

type ConnSet map[net.Conn]struct{}

type DefaultBinaryParser

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

一个默认的二进制解析器,即leaf自带的实现 -------------- | len | data | --------------

func NewDefaultParser

func NewDefaultParser() *DefaultBinaryParser

func (*DefaultBinaryParser) Read

func (p *DefaultBinaryParser) Read(conn *Conn) ([]byte, error)

goroutine safe

func (*DefaultBinaryParser) SetByteOrder

func (p *DefaultBinaryParser) SetByteOrder(littleEndian bool)

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

func (*DefaultBinaryParser) SetMsgLen

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

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

func (*DefaultBinaryParser) Write

func (p *DefaultBinaryParser) Write(conn *Conn, args ...[]byte) error

goroutine safe

type IParser

type IParser interface {
	Read(conn *Conn) ([]byte, error)
	Write(conn *Conn, args ...[]byte) error
}

type Option

type Option func(*Client)

func ConnNum

func ConnNum(num int) Option

func ConnectInterval

func ConnectInterval(dr time.Duration) Option

func Parser

func Parser(p IParser) Option

type Server

type Server struct {
	Addr            string
	MaxConnNum      int
	PendingWriteNum int
	NewAgent        func(*Conn) network.Agent

	// msg parser
	Parser IParser
	// contains filtered or unexported fields
}

func (*Server) Close

func (server *Server) Close()

func (*Server) Start

func (server *Server) Start()

Jump to

Keyboard shortcuts

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