lib

package
v0.0.0-...-2f74b22 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosing   = errors.New("use of closed network connection")
	ErrWriteBlocking = errors.New("write packet was blocking")
	ErrReadBlocking  = errors.New("read packet was blocking")
)

Error type

Functions

func Float642String

func Float642String(val float64) string

Float642String convert from int to string

func Int2String

func Int2String(val int) string

Int2String convert from int to string

func Int642String

func Int642String(val int64) string

Int642String convert from int64 to string

func NewUUID

func NewUUID() string

NewUUID get a new UUID

func String2Int

func String2Int(val string) int

String2Int convert from string to int

func Uint322ByteArray

func Uint322ByteArray(val uint32) []byte

Uint322ByteArray uint32 to byte array

func Uint322String

func Uint322String(val uint32) string

Uint322String convert from uint32 to string

Types

type Config

type Config struct {
	PacketSendChanLimit    uint32 // the limit of packet send channel
	PacketReceiveChanLimit uint32 // the limit of packet receive channel
}

Config struct

type Conn

type Conn struct {
	PeerID uint32
	RoomID string
	// contains filtered or unexported fields
}

Conn exposes a set of callbacks for the various events that occur on a connection

func (*Conn) AsyncWritePacket

func (c *Conn) AsyncWritePacket(p Packet, timeout time.Duration) (err error)

AsyncWritePacket async writes a packet, this method will never block

func (*Conn) Close

func (c *Conn) Close()

Close closes the connection

func (*Conn) Do

func (c *Conn) Do()

Do it

func (*Conn) GetExtraData

func (c *Conn) GetExtraData() interface{}

GetExtraData gets the extra data from the Conn

func (*Conn) GetRawConn

func (c *Conn) GetRawConn() *net.TCPConn

GetRawConn returns the raw net.TCPConn from the Conn

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed indicates whether or not the connection is closed

func (*Conn) PutExtraData

func (c *Conn) PutExtraData(data interface{})

PutExtraData puts the extra data with the Conn

type ConnCallback

type ConnCallback interface {
	// OnConnect is called when the connection was accepted,
	// If the return value of false is closed
	OnConnect(*Conn) bool

	// OnMessage is called when the connection receives a packet,
	// If the return value of false is closed
	OnMessage(*Conn, Packet) bool

	// OnClose is called when the connection closed
	OnClose(*Conn)
}

ConnCallback is an interface of methods that are used as callbacks on a connection

type IntHeap

type IntHeap []uint32

An IntHeap is a min-heap of ints.

func (IntHeap) Len

func (h IntHeap) Len() int

func (IntHeap) Less

func (h IntHeap) Less(i, j int) bool

func (*IntHeap) Pop

func (h *IntHeap) Pop() interface{}

Pop pop a int element

func (*IntHeap) Push

func (h *IntHeap) Push(x interface{})

Push push a int element

func (IntHeap) Swap

func (h IntHeap) Swap(i, j int)

type Packet

type Packet interface {
	Serialize() []byte
}

Packet interface

type Protocol

type Protocol interface {
	ReadPacket(conn *net.TCPConn) (Packet, error)
}

Protocol interface

type Server

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

Server struct

func NewServer

func NewServer(config *Config, callback ConnCallback, protocol Protocol) *Server

NewServer creates a server

func (*Server) Start

func (s *Server) Start(listener *net.TCPListener, acceptTimeout time.Duration)

Start starts service

func (*Server) Stop

func (s *Server) Stop()

Stop stops service

type Stack

type Stack []interface{}

Stack can save any types

func (*Stack) Cap

func (stack *Stack) Cap() int

Cap get the cap of stack

func (*Stack) IsEmpty

func (stack *Stack) IsEmpty() bool

IsEmpty judge if the stack is empty

func (*Stack) Length

func (stack *Stack) Length() int

Length get the length of Stack

func (*Stack) Pop

func (stack *Stack) Pop() (interface{}, error)

Pop pop a element from Stack

func (*Stack) Push

func (stack *Stack) Push(value interface{})

Push push a element to Stack

func (*Stack) Top

func (stack *Stack) Top() (interface{}, error)

Top get the top element of the Stack

Jump to

Keyboard shortcuts

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