netengine

package module
v0.0.0-...-e183b9b Latest Latest
Warning

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

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

README

netengine-go

netengine in golang

NetNotify

type SendFunc func(data []byte) error
type NetNotify interface {
	OnAccepted(listenid int, con net.Conn)

	/* return -1 to close
	return >0 to consume data
	return 0 need more data
	use send to send data get more performance
	data is valid only in OnRecv, so careful to use it
	*/
	OnRecv(id int, data []byte, send SendFunc) int

	// OnClosed,OnBufferLimit,OnAccept不会在同一个goroute中调用
	OnClosed(id int)
	// write buffer limit, OnClosed always will call
	OnBufferLimit(id int)
}

server

neten := new(NetEngine)
neten.Init()
lis, err := net.Listen("tcp", "127.0.0.1:9000")
id, err := neten.AddListen(lis, &sernotify)
neten.Start(id)


OnAccepted:
id,err := neten.AddConnection(conn, &sernotify, ...)
neten.Start(id)

client

neten := new(NetEngine)
neten.Init()
conn, err := net.Dial("tcp", "127.0.0.1:9000")
id,err := neten.AddConnection(conn, &clinotify, ...)
neten.Start(id)
// send is asynchronous
neten.Send(id, data)
neten.Close(id)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NetEngine

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

func (*NetEngine) AddConnection

func (c *NetEngine) AddConnection(con net.Conn, notify NetNotify, recvBufLen, maxSendBufLen int, readTimeout, writeTimeout time.Duration) (id int, err error)

func (*NetEngine) AddListen

func (c *NetEngine) AddListen(lis net.Listener, notify NetNotify) (id int, err error)

func (*NetEngine) Close

func (c *NetEngine) Close(id int)

func (*NetEngine) GetLocalAddr

func (c *NetEngine) GetLocalAddr(id int) (net.Addr, bool)

func (*NetEngine) GetRemoteAddr

func (c *NetEngine) GetRemoteAddr(id int) (net.Addr, bool)

func (*NetEngine) GetSendFunc

func (c *NetEngine) GetSendFunc(id int) SendFunc

SendFunc is synchronous

func (*NetEngine) Init

func (c *NetEngine) Init() error

func (*NetEngine) Send

func (c *NetEngine) Send(id int, data []byte)

Send is asynchronous,不会持有data

func (*NetEngine) Start

func (c *NetEngine) Start(id int)

Listen or CoonnectTo SetBuffer;SetCloseTime Start

func (*NetEngine) Stop

func (c *NetEngine) Stop()

type NetNotify

type NetNotify interface {
	/* 同一个listenid 会在一个goroute中调用,
	新的连接需要手动, id,err := AddConnection Start(id)
	*/
	OnAccepted(listenid int, con net.Conn)

	/* return -1 to close
	return >0 to consume data
	return 0 need more data
	use send to send data get more performance
	data is valid only in OnRecv, so careful to use it
	*/
	OnRecv(id int, data []byte, send SendFunc) int

	// OnClosed,OnBufferLimit,OnAccept不会在同一个goroute中调用
	OnClosed(id int)
	// write buffer limit, OnClosed always will call
	OnBufferLimit(id int)
}

type SendFunc

type SendFunc func(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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