net

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoxConnClose = iota
	BoxConnConnecting
)
View Source
const (
	StatusIdle = iota
	StatusRunning
	StatusShutdown
	StatusStopped
)
View Source
const (
	EventAccept      = iota //accept net connected from peer
	EventReqConnect         //request for connecting to remote
	EventRespConnect        //connect to remote successfully
	EventReceive            //receive Data
	EventClose              //Conn has been closed
	EventShutdown           //server shut down !
	EventMaxFlag            //network event  end
)
View Source
const (
	DefaultSocketBufferSize = 1024 * 64
)

Variables

View Source
var BoxConn = makeGnetConn

BoxConn create new box conn, param: gnet.Conn

View Source
var BoxConnector = makeConnector

BoxConnector client connector, param: serverEH

View Source
var BoxLoop = makeGnetLoop

BoxLoop box network loop, listen or connect, param: NetEventQueue

Functions

This section is empty.

Types

type AcceptEvent

type AcceptEvent struct {
	Addr string
	Conn IBoxConn // net work channel
}

AcceptEvent accept or connect

type ClosedEvent

type ClosedEvent struct {
	TSid string //Conn handle address
}

ClosedEvent conn has been closed by network framework

type ConnectEvent

type ConnectEvent struct {
	Host string //peer address
	Conn IBoxConn
}

ConnectEvent connect successfully

type ConnectToEvent

type ConnectToEvent struct {
	Name    string
	Network string
	Addr    string
}

type EventData

type EventData struct {
	NetType EventType   //event type
	Data    interface{} //event Data
	Err     error       //err info
}

func GetEventData

func GetEventData() *EventData

GetEventData TODO replace with object pool

type EventType

type EventType uint8

type IBoxConn

type IBoxConn interface {
	// LocalAddr is the connection's local socket address.
	LocalAddr() (addr net.Addr)
	// RemoteAddr is the connection's remote peer address.
	RemoteAddr() (addr net.Addr)

	// Read reads data from the connection.
	Read(b []byte) (n int, err error)

	// Write writes one byte slice to peer asynchronously, usually you would call it in individual goroutines
	Write(buf []byte) error

	// Close closes the current connection.
	Close() error

	// IsClose will return ture if connection has been closed
	IsClose() bool

	OnClose()
}

IBoxConn box net connection wrapper !

type IBoxConnector

type IBoxConnector interface {
	//Start connector logic
	Start() error
	//ConnectTo connect to address
	ConnectTo(network, address string) (IBoxConn, error)
	//Stop all connect
	Stop() error
}

IBoxConnector connector wrapper

type IBoxNetLoop

type IBoxNetLoop interface {
	//Start create network loop
	Start() error
	//Shutdown will set closed all connections and refuse new connections, it will not stop network loop
	Shutdown() error
	//Stop all network loop
	Stop() error
	//Tick network goroutine tick func
	Tick()
	//Notify logic goroutine net event
	Notify(data *EventData)
	//SendToLoop send event to network goroutine, deal by tick function
	SendToLoop(data *EventData)
	//ConnectTo connect to remote server
	ConnectTo(network, address string) (IBoxConn, error)
	//ListenAt listen at address
	ListenAt(network, address string) error
}

IBoxNetLoop box network loop

type NetEventQueue

type NetEventQueue chan *EventData

NetEventQueue event channel type

type Option added in v0.4.27

type Option func(*Options)

func WithNetworkQueue added in v0.4.27

func WithNetworkQueue(networkMq NetEventQueue) Option

func WithSocketBufferSize added in v0.4.27

func WithSocketBufferSize(bufferSize int) Option

type Options added in v0.4.27

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

type ReceiveEvent

type ReceiveEvent struct {
	TSid string //peer address
	Data []byte //receive Data package
}

ReceiveEvent Conn receive Data from peer

Jump to

Keyboard shortcuts

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