util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxPacket  = errors.New("packet over size")
	ErrMinPacket  = errors.New("packet short size")
	ErrShortMsgID = errors.New("short msgid")
)
View Source
var (
	ErrInvalidPortRange = errors.New("invalid port range")
)

Functions

func CompressBytes

func CompressBytes(data []byte) ([]byte, error)

func DecompressBytes

func DecompressBytes(data []byte) ([]byte, error)

func DetectPort

func DetectPort(addr string, fn func(string) (interface{}, error)) (interface{}, error)

在给定的端口范围内找到一个能用的端口 格式: localhost:5000~6000

func FileExists

func FileExists(name string) bool

func FileSize

func FileSize(name string) int64

func GetLocalIP

func GetLocalIP() string

获取本地IP地址,有多重IP时,默认取第一个

func GetPrivateIPv4

func GetPrivateIPv4() ([]*net.IPAddr, error)

GetPrivateIPv4 returns the list of private network IPv4 addresses on all active interfaces.

func GetPublicIPv6

func GetPublicIPv6() ([]*net.IPAddr, error)

GetPublicIPv6 returns the list of all public IPv6 addresses on all active interfaces.

func GetRemoteAddrss

func GetRemoteAddrss(ses cellnet.Session) (string, bool)

获取session远程的地址

func IsEOFOrNetReadError

func IsEOFOrNetReadError(err error) bool

func JoinAddress

func JoinAddress(host string, port int) string

将ip和端口合并为地址

func ReadFileLines

func ReadFileLines(filename string, callback func(line string) bool) error

读取文本文件的所有行

func RecvLTVPacket

func RecvLTVPacket(reader io.Reader, maxPacketSize int) (msg interface{}, err error)

接收Length-Type-Value格式的封包流程

func SendLTVPacket

func SendLTVPacket(writer io.Writer, ctx cellnet.ContextSet, data interface{}) error

发送Length-Type-Value格式的封包流程

func SpliteAddress

func SpliteAddress(addr string) (host string, port int, err error)

将地址拆分为ip和端口

func StringHash

func StringHash(s string) (hash uint16)

字符串转为16位整形值

func WriteFull

func WriteFull(writer io.Writer, buf []byte) error

完整发送所有封包

Types

type Queue

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

func NewQueue

func NewQueue(size int) *Queue

func (*Queue) Count

func (self *Queue) Count() int

func (*Queue) Dequeue

func (self *Queue) Dequeue() (ret interface{})

func (*Queue) Enqueue

func (self *Queue) Enqueue(data interface{})

func (*Queue) Peek

func (self *Queue) Peek() interface{}

Jump to

Keyboard shortcuts

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