net

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoxConnClose = iota
	BoxConnConnecting
)
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
)

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 start connector logic
	Start() error
	//ConnectTo connect to address
	ConnectTo(network, address string) (IBoxConn, error)
	//Stop stop all connect
	Stop() error
}

IBoxConnector connector wrapper

type IBoxNetLoop

type IBoxNetLoop interface {
	//Start create network loop
	Start() error
	//Stop stop all nerwork loop
	Stop() error
	//Tick network goroutine tick func
	Tick()
	//Notify 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 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