netutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LengthNeedSize  = 4
	MaxPacketLength = 4 * 1024 * 1024 // 4M
)

Variables

View Source
var NullSession = nullSession{}

Functions

func KeepAliveTCPConn

func KeepAliveTCPConn(conn net.Conn, d time.Duration)

func ListenAndServeTCP

func ListenAndServeTCP(addrStr string, handler func(net.Conn), async bool, certs ...tls.Certificate) error

func ListenAndServeUDP

func ListenAndServeUDP(addrStr string, handler func(*net.UDPConn), async bool) error

func ListenAndServeWebsocket

func ListenAndServeWebsocket(addrStr, path string, handler func(net.Conn), async bool) error

Types

type BytesPacket

type BytesPacket []byte

func (BytesPacket) Bytes

func (p BytesPacket) Bytes() []byte

func (BytesPacket) Len

func (p BytesPacket) Len() int

type Packet

type Packet interface {
	Len() int
	Bytes() []byte
}

type PacketHandler

type PacketHandler func(b []byte)

type PacketReader

type PacketReader interface {
	Conn() net.Conn
	ReadPacket() (n int, err error)
	SetTimeout(d time.Duration)
}

PacketReader reads a network packet

func NewPacketReader

func NewPacketReader(conn net.Conn, packetHandler PacketHandler) PacketReader

NewPacketReader creates a PacketReader with net.Conn and PacketHandler

type RWSession

type RWSession struct {
	*WSession
	// contains filtered or unexported fields
}

Readable and Writable Session

func NewRWSession

func NewRWSession(
	id string,
	conWriteSize int,
	packetReader PacketReader,
) *RWSession

func (*RWSession) Run

func (s *RWSession) Run(onNewSession, onQuitSession func())

type Session

type Session interface {
	Id() string
	Closed() bool
	Send(Packet)
	Run(onNewSession, onQuitSession func())
	Quit()
}

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
	// contains filtered or unexported fields
}

func NewTCPKeepAliveListener

func NewTCPKeepAliveListener(ln *net.TCPListener, d time.Duration) *TCPKeepAliveListener

func (TCPKeepAliveListener) Accept

func (ln TCPKeepAliveListener) Accept() (c net.Conn, err error)

type WSession

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

Write-only Session

func NewWSession

func NewWSession(id string, conn net.Conn, conWriteSize int) *WSession

func (*WSession) Closed

func (ws *WSession) Closed() bool

func (*WSession) Id

func (ws *WSession) Id() string

func (*WSession) Quit

func (ws *WSession) Quit()

func (*WSession) Run

func (ws *WSession) Run(onNewSession, onQuitSession func())

func (*WSession) Send

func (ws *WSession) Send(p Packet)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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