netutil

package
v0.0.0-...-b1bf5db Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeepAliveTCPConn

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

func ListenAndServeTCP

func ListenAndServeTCP(addrStr string, handler func(net.Conn), async bool) 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

func ListenSignal

func ListenSignal(handler func(sig os.Signal) (ret bool), signals ...os.Signal)

func NewTCPKeepAliveListener

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

Types

type CrypterFunc

type CrypterFunc func(dst, src []byte)

type DecryptFunc

type DecryptFunc func(dst, src []byte)

type PacketHander

type PacketHander func(packet []byte)

type RWSession

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

可读可写的Session

func NewRWSession

func NewRWSession(conn net.Conn, rstream StreamReader, id string, conWriteSize int) *RWSession

func (*RWSession) Run

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

func (*RWSession) SetDecrypter

func (s *RWSession) SetDecrypter(decrypter CrypterFunc)

type ReadStream

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

func NewReadStream

func NewReadStream(conn net.Conn, onRecvPacket PacketHander) *ReadStream

通用的流读取

func (*ReadStream) Conn

func (r *ReadStream) Conn() net.Conn

func (*ReadStream) Read

func (r *ReadStream) Read() (int, error)

func (*ReadStream) SetByteNumForLength

func (r *ReadStream) SetByteNumForLength(n int)

func (*ReadStream) SetDecodeLengthFunc

func (r *ReadStream) SetDecodeLengthFunc(decodeLengthFunc func([]byte) int)

func (*ReadStream) SetDecrypter

func (r *ReadStream) SetDecrypter(decrypter DecryptFunc)

func (*ReadStream) SetTimeout

func (r *ReadStream) SetTimeout(d time.Duration)

type Session

type Session interface {
	Id() string
	Send(*buffer.Buffer)
	Run(onNewSession, onQuitSession func())
	Quit()
	SetEncrypter(encrypter CrypterFunc)
	SetDecrypter(decrypter CrypterFunc)
}

type StreamReader

type StreamReader interface {
	Conn() net.Conn
	Read() (n int, err error)
	SetDecrypter(decrypter DecryptFunc)
	SetTimeout(d time.Duration)
}

序列化后的数据流的读取

type UDPConn

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

用于只写的UDP连接,实现 net.Conn 接口

func NewUDPConn

func NewUDPConn(localConn *net.UDPConn, remoteAddr *net.UDPAddr) *UDPConn

func (*UDPConn) Close

func (conn *UDPConn) Close() error

func (*UDPConn) LocalAddr

func (conn *UDPConn) LocalAddr() net.Addr

func (*UDPConn) Read

func (conn *UDPConn) Read(b []byte) (int, error)

func (*UDPConn) RemoteAddr

func (conn *UDPConn) RemoteAddr() net.Addr

func (*UDPConn) SetDeadline

func (conn *UDPConn) SetDeadline(t time.Time) error

func (*UDPConn) SetReadDeadline

func (conn *UDPConn) SetReadDeadline(t time.Time) error

func (*UDPConn) SetWriteDeadline

func (conn *UDPConn) SetWriteDeadline(t time.Time) error

func (*UDPConn) Write

func (conn *UDPConn) Write(b []byte) (int, error)

type UDPReadStream

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

UDP 包读取

func NewUDPReadStream

func NewUDPReadStream(conn *net.UDPConn, onRecvPacket PacketHander) *UDPReadStream

func (*UDPReadStream) Conn

func (r *UDPReadStream) Conn() net.Conn

func (*UDPReadStream) Read

func (r *UDPReadStream) Read(CrypterFunc) (int, error)

func (*UDPReadStream) SetDecrypter

func (r *UDPReadStream) SetDecrypter(CrypterFunc)

func (*UDPReadStream) SetTimeout

func (r *UDPReadStream) SetTimeout(d time.Duration)

type WSession

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

只写的Session

func NewWSession

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

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(b *buffer.Buffer)

func (*WSession) SetEncrypter

func (ws *WSession) SetEncrypter(encrypter CrypterFunc)

Jump to

Keyboard shortcuts

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