xnet

package
v0.0.0-...-20d904f Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitToMask

func BitToMask(bit int) string

func GetFreeTCPPort

func GetFreeTCPPort() (int, error)

func GetFreeUDPPort

func GetFreeUDPPort() (int, error)

func GetIPV4Address

func GetIPV4Address() []string

func GetIPV6Address

func GetIPV6Address(global bool) []string

func GetNetTCPListener

func GetNetTCPListener(addr string, dupFd uintptr) (*net.TCPListener, error)

func IP4ToInt

func IP4ToInt(str string) uint32

func InetAton

func InetAton(ipnr string) int64

func InetNtoa

func InetNtoa(ipnr int64) net.IP

func IsPublicIP

func IsPublicIP(IP net.IP) bool

func MaskToBit

func MaskToBit(str string) int

Types

type ConnEx

type ConnEx struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewTLSTcpClient

func NewTLSTcpClient(address string, timeout int, config *TLSConfig) (*ConnEx, error)

func NewTcpClient

func NewTcpClient(address string, timeout int) (*ConnEx, error)

func NewUnixClient

func NewUnixClient(filename string) (*ConnEx, error)

func (*ConnEx) AppendHeaderBuffer

func (me *ConnEx) AppendHeaderBuffer(buf []byte)

func (*ConnEx) CheckBuffer

func (me *ConnEx) CheckBuffer(maxBuf int)

func (*ConnEx) Close

func (me *ConnEx) Close()

func (*ConnEx) Connect

func (me *ConnEx) Connect() (bool, error)

func (*ConnEx) ConnectTLS

func (me *ConnEx) ConnectTLS() (bool, error)

func (*ConnEx) GetData

func (me *ConnEx) GetData() []byte

func (*ConnEx) GetDataBuffer

func (me *ConnEx) GetDataBuffer() *bytes.Buffer

func (*ConnEx) GetDataLen

func (me *ConnEx) GetDataLen() int

func (*ConnEx) GetFd

func (me *ConnEx) GetFd() uintptr

func (*ConnEx) GetHeaderBuffer

func (me *ConnEx) GetHeaderBuffer() []byte

func (*ConnEx) GetHeaderLen

func (me *ConnEx) GetHeaderLen() int

func (*ConnEx) GetHeaderLength

func (me *ConnEx) GetHeaderLength() int

func (*ConnEx) GetHeaderMsg

func (me *ConnEx) GetHeaderMsg() interface{}

func (*ConnEx) GetHost

func (me *ConnEx) GetHost() string

func (*ConnEx) GetIf

func (me *ConnEx) GetIf() ConnExIf

func (*ConnEx) GetLastRecvPacket

func (me *ConnEx) GetLastRecvPacket() int64

func (*ConnEx) GetLastUpdate

func (me *ConnEx) GetLastUpdate() int64

func (*ConnEx) GetPktNum

func (me *ConnEx) GetPktNum() int64

func (*ConnEx) GetRecvTimeout

func (me *ConnEx) GetRecvTimeout() int

func (*ConnEx) Init

func (me *ConnEx) Init()

func (*ConnEx) IsConnected

func (me *ConnEx) IsConnected() bool

func (*ConnEx) ReadEx

func (me *ConnEx) ReadEx() (int, error, bool)

func (*ConnEx) ReadExBuffer

func (me *ConnEx) ReadExBuffer(inBuf []byte, retLen *int) (int, error, bool)

ReadExBuffer return ok, error, timeout

func (*ConnEx) ReadLen

func (me *ConnEx) ReadLen(len int) (int, error)

func (*ConnEx) Reset

func (me *ConnEx) Reset()

func (*ConnEx) SendDequeue

func (me *ConnEx) SendDequeue() []byte

func (*ConnEx) SendEnqueue

func (me *ConnEx) SendEnqueue(data []byte)

func (*ConnEx) SetConn

func (me *ConnEx) SetConn(conn net.Conn)

func (*ConnEx) SetConnTimeout

func (me *ConnEx) SetConnTimeout(ms int)

func (*ConnEx) SetHeaderLen

func (me *ConnEx) SetHeaderLen(len int)

func (*ConnEx) SetHost

func (me *ConnEx) SetHost(host string)

func (*ConnEx) SetIf

func (me *ConnEx) SetIf(connIf ConnExIf)

func (*ConnEx) SetMaxDataLen

func (me *ConnEx) SetMaxDataLen(v int)

func (*ConnEx) SetReadBuffer

func (me *ConnEx) SetReadBuffer(size int)

func (*ConnEx) SetRecvTimeout

func (me *ConnEx) SetRecvTimeout(ms int)

func (*ConnEx) SetSendTimeout

func (me *ConnEx) SetSendTimeout(ms int)

func (*ConnEx) SetWriteBuffer

func (me *ConnEx) SetWriteBuffer(size int)

type ConnExIf

type ConnExIf interface {
	ParseHeader(b []byte) (dataLen int, headerMsg interface{})
}

type ConnExIfImp

type ConnExIfImp struct {
	ParseHeaderFunc func(b []byte) (dataLen int, headerMsg interface{})
}

func NewConnExIfImp

func NewConnExIfImp(parseHeader func(b []byte) (dataLen int, headerMsg interface{})) *ConnExIfImp

func (*ConnExIfImp) ParseHeader

func (me *ConnExIfImp) ParseHeader(b []byte) (dataLen int, headerMsg interface{})

type DefaultMsgHeader

type DefaultMsgHeader struct {
	MsgLen  int32
	MsgType int32
}

type MacIP

type MacIP struct {
	Name string
	Mac  string
	IPS  []_IP
}

func GetMacIP

func GetMacIP() ([]MacIP, error)

func (*MacIP) IPV6Address

func (me *MacIP) IPV6Address(global bool) []string

type MyServer

type MyServer struct {
	IPFilterEnable bool
	ClientMap      xmap.Map[int64, *MySrvClient]

	ServerName string

	TimeoutFunc  func(client *MySrvClient)
	WriterFunc   func(client *MySrvClient)
	ReadFunc     func(server *MyServer, client *MySrvClient) bool
	IncomingData func(server *MyServer, client *MySrvClient, buf []byte)

	MaxIdleTime int64
	GraceFd     uintptr
	// contains filtered or unexported fields
}

func NewMyServer

func NewMyServer(bindHost string) *MyServer

func (*MyServer) GetClient

func (me *MyServer) GetClient() xmap.Map[int64, *MySrvClient]

func (*MyServer) GetClientById

func (me *MyServer) GetClientById(id int64) *MySrvClient

func (*MyServer) GetClientCount

func (me *MyServer) GetClientCount() int

func (*MyServer) GetUserData

func (me *MyServer) GetUserData() interface{}

func (*MyServer) ParseHeader

func (me *MyServer) ParseHeader(b []byte) (int, interface{})

func (*MyServer) SetInterface

func (me *MyServer) SetInterface(srvInf MySrvInf)

func (*MyServer) SetSendBuffer

func (me *MyServer) SetSendBuffer(size int64)

func (*MyServer) SetUserData

func (me *MyServer) SetUserData(data interface{})

func (*MyServer) Start

func (me *MyServer) Start() (bool, error)

func (*MyServer) Stop

func (me *MyServer) Stop()

type MySrvClient

type MySrvClient struct {

	/////////////////////////////////////////////////////////
	IsLogin    cast.Bool
	DecodeMode int
	// contains filtered or unexported fields
}

func (*MySrvClient) EnableKeepAlive

func (me *MySrvClient) EnableKeepAlive(interval, count int) error

警告: 会引起socket超时失败

func (*MySrvClient) ForceClose

func (me *MySrvClient) ForceClose(arg ...int)

second

func (*MySrvClient) GetClientID

func (me *MySrvClient) GetClientID() int64

func (*MySrvClient) GetCloseError

func (me *MySrvClient) GetCloseError() string

///////////////////////////////////////////////////////////////////////////////////////

func (*MySrvClient) GetConn

func (me *MySrvClient) GetConn() *ConnEx

func (*MySrvClient) GetCreateTime

func (me *MySrvClient) GetCreateTime() int64

func (*MySrvClient) GetDefaultHeader

func (me *MySrvClient) GetDefaultHeader() *DefaultMsgHeader

func (*MySrvClient) GetIP

func (me *MySrvClient) GetIP() string

func (*MySrvClient) GetRemoteAddressString

func (me *MySrvClient) GetRemoteAddressString() string

func (*MySrvClient) GetSendQueueLen

func (me *MySrvClient) GetSendQueueLen() int

func (*MySrvClient) GetUserData

func (me *MySrvClient) GetUserData() interface{}

func (*MySrvClient) IsClose

func (me *MySrvClient) IsClose() bool

func (*MySrvClient) Send

func (me *MySrvClient) Send(data []byte, copy ...bool) bool

func (*MySrvClient) SendDequeue

func (me *MySrvClient) SendDequeue() *sendQueue

func (*MySrvClient) SendNoHeader

func (me *MySrvClient) SendNoHeader(msgType int32, data []byte, dataLen int) bool

func (*MySrvClient) SetUserData

func (me *MySrvClient) SetUserData(data interface{})

func (*MySrvClient) Write

func (me *MySrvClient) Write(p []byte) (int, error)

type MySrvInf

type MySrvInf interface {
	//false: refuse connect
	OnAccept(client *MySrvClient) bool
	OnClose(client *MySrvClient)
	//false: disconnect
	OnRequest(client *MySrvClient, data []byte) bool
}

type MySrvInfImp

type MySrvInfImp struct {
	AcceptFunc  func(client *MySrvClient) bool
	CloseFunc   func(client *MySrvClient)
	RequestFunc func(client *MySrvClient, data []byte) bool
}

func NewMySrvInf

func NewMySrvInf(accept func(client *MySrvClient) bool,
	close func(client *MySrvClient),
	request func(client *MySrvClient, data []byte) bool) *MySrvInfImp

func (*MySrvInfImp) OnAccept

func (me *MySrvInfImp) OnAccept(client *MySrvClient) bool

func (*MySrvInfImp) OnClose

func (me *MySrvInfImp) OnClose(client *MySrvClient)

func (*MySrvInfImp) OnRequest

func (me *MySrvInfImp) OnRequest(client *MySrvClient, data []byte) bool

type NetExHeaderMsg

type NetExHeaderMsg struct {
	MsgLen  int32
	MsgType int32
	MsgID   int32
}

type TLSConfig

type TLSConfig struct {
	CA         string
	Cert       string
	Key        string
	AuthClient bool
}

type TcpListenerEx

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

func NewTLSTcpServer

func NewTLSTcpServer(host string, fd uintptr, config *TLSConfig) (*TcpListenerEx, error)

func NewTcpServer

func NewTcpServer(host string, fd uintptr) (*TcpListenerEx, error)

func (*TcpListenerEx) Accept

func (me *TcpListenerEx) Accept() (*ConnEx, error)

Jump to

Keyboard shortcuts

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