netutil

package
v0.0.0-...-fae5011 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIN_PAYLOAD_CAP = 128
	CAP_GROW_SHIFT  = uint(2)

	PAYLOAD_LEN_MASK    = 0x7FFFFFFF
	COMPRESSED_BIT_MASK = 0x80000000
)
View Source
const (
	PACKET_SIZE_SMALL = 1024
	PACKET_SIZE_BIG   = 1024 * 64
	PACKET_SIZE_HUGE  = 1024 * 1024 * 4
)
View Source
const (
	MAX_PACKET_SIZE    = 25 * 1024 * 1024
	SIZE_FIELD_SIZE    = 4
	PREPAYLOAD_SIZE    = SIZE_FIELD_SIZE
	MAX_PAYLOAD_LENGTH = MAX_PACKET_SIZE - PREPAYLOAD_SIZE
)
View Source
const (
	RESTART_TCP_SERVER_INTERVAL = 3 * time.Second
)
View Source
const (
	SEND_BUFFER_SIZE = 8192 * 2
)

Variables

View Source
var (
	PACKET_ENDIAN                = binary.LittleEndian
	PREDEFINE_PAYLOAD_CAPACITIES []uint32
)
View Source
var (
	NETWORK_ENDIAN = binary.LittleEndian
)

Functions

func ConnectTCP

func ConnectTCP(host string, port int) (net.Conn, error)

func IsConnectionError

func IsConnectionError(_err interface{}) bool

func IsTemporaryNetError

func IsTemporaryNetError(err error) bool

func ReadAll

func ReadAll(conn io.Reader, data []byte) error

func ReadLine

func ReadLine(conn net.Conn) (string, error)

func ServeForever

func ServeForever(f interface{}, args ...interface{})

func ServeTCP

func ServeTCP(listenAddr string, delegate TCPServerDelegate) error

func ServeTCPForever

func ServeTCPForever(listenAddr string, delegate TCPServerDelegate)

func WriteAll

func WriteAll(conn io.Writer, data []byte) error

Types

type BufferedConnection

type BufferedConnection struct {
	Connection
	sync.Mutex
	// contains filtered or unexported fields
}

func NewBufferedConnection

func NewBufferedConnection(conn Connection, delay time.Duration) *BufferedConnection

func (*BufferedConnection) Close

func (bc *BufferedConnection) Close() error

func (*BufferedConnection) Read

func (bc *BufferedConnection) Read(p []byte) (n int, err error)

func (*BufferedConnection) String

func (bc *BufferedConnection) String() string

func (*BufferedConnection) Write

func (bc *BufferedConnection) Write(p []byte) (n int, err error)

type BufferedReadConnection

type BufferedReadConnection struct {
	Connection
	// contains filtered or unexported fields
}

func NewBufferedReadConnection

func NewBufferedReadConnection(conn Connection) *BufferedReadConnection

func (*BufferedReadConnection) Read

func (brc *BufferedReadConnection) Read(p []byte) (int, error)

type CompressedConnection

type CompressedConnection struct {
	Connection
	// contains filtered or unexported fields
}

func NewCompressedConnection

func NewCompressedConnection(conn Connection) *CompressedConnection

func (*CompressedConnection) Close

func (cc *CompressedConnection) Close() error

func (*CompressedConnection) Flush

func (cc *CompressedConnection) Flush() error

func (*CompressedConnection) Read

func (cc *CompressedConnection) Read(p []byte) (int, error)

func (*CompressedConnection) Write

func (cc *CompressedConnection) Write(p []byte) (int, error)

type Connection

type Connection interface {
	io.ReadWriteCloser
	Flush() error

	RemoteAddr() net.Addr
	LocalAddr() net.Addr
	SetWriteDeadline(time.Time) error
	SetReadDeadline(time.Time) error
}

type GobMsgPacker

type GobMsgPacker struct{}

func (GobMsgPacker) PackMsg

func (mp GobMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

func (GobMsgPacker) UnpackMsg

func (mp GobMsgPacker) UnpackMsg(data []byte, msg interface{}) error

type JSONMsgPacker

type JSONMsgPacker struct {
}

func (JSONMsgPacker) PackMsg

func (mp JSONMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

func (JSONMsgPacker) UnpackMsg

func (mp JSONMsgPacker) UnpackMsg(data []byte, msg interface{}) error

type MessagePackMsgPacker

type MessagePackMsgPacker struct{}

func (MessagePackMsgPacker) PackMsg

func (mp MessagePackMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

func (MessagePackMsgPacker) UnpackMsg

func (mp MessagePackMsgPacker) UnpackMsg(data []byte, msg interface{}) error

type MsgPacker

type MsgPacker interface {
	PackMsg(msg interface{}, buf []byte) ([]byte, error)
	UnpackMsg(data []byte, msg interface{}) error
}
var (
	MSG_PACKER MsgPacker = MessagePackMsgPacker{}
)

type NetConnection

type NetConnection struct {
	net.Conn
}

func (NetConnection) Flush

func (c NetConnection) Flush() error

type Packet

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

func NewPacket

func NewPacket() *Packet

func (*Packet) AddRefCount

func (p *Packet) AddRefCount(add int64)

func (*Packet) AppendArgs

func (p *Packet) AppendArgs(args []interface{})

Append arguments to packet one by one

func (*Packet) AppendBool

func (p *Packet) AppendBool(b bool)

func (*Packet) AppendByte

func (p *Packet) AppendByte(b byte)

func (*Packet) AppendBytes

func (p *Packet) AppendBytes(v []byte)

func (*Packet) AppendClientID

func (p *Packet) AppendClientID(id common.ClientID)

func (*Packet) AppendData

func (p *Packet) AppendData(msg interface{})

func (*Packet) AppendEntityID

func (p *Packet) AppendEntityID(id common.EntityID)

func (*Packet) AppendFloat32

func (p *Packet) AppendFloat32(f float32)

func (*Packet) AppendFloat64

func (p *Packet) AppendFloat64(f float64)

func (*Packet) AppendStringList

func (p *Packet) AppendStringList(list []string)

func (*Packet) AppendUint16

func (p *Packet) AppendUint16(v uint16)

func (*Packet) AppendUint32

func (p *Packet) AppendUint32(v uint32)

func (*Packet) AppendUint64

func (p *Packet) AppendUint64(v uint64)

func (*Packet) AppendVarBytes

func (p *Packet) AppendVarBytes(v []byte)

func (*Packet) AppendVarStr

func (p *Packet) AppendVarStr(s string)

func (*Packet) ClearPayload

func (p *Packet) ClearPayload()

func (*Packet) GetPayloadLen

func (p *Packet) GetPayloadLen() uint32

func (*Packet) Payload

func (p *Packet) Payload() []byte

func (*Packet) PayloadCap

func (p *Packet) PayloadCap() uint32

func (*Packet) PopUint32

func (p *Packet) PopUint32() (v uint32)

func (*Packet) ReadArgs

func (p *Packet) ReadArgs() [][]byte

func (*Packet) ReadBool

func (p *Packet) ReadBool() (v bool)

func (*Packet) ReadByte

func (p *Packet) ReadByte() (v byte)

func (*Packet) ReadBytes

func (p *Packet) ReadBytes(size uint32) []byte

func (*Packet) ReadClientID

func (p *Packet) ReadClientID() common.ClientID

func (*Packet) ReadData

func (p *Packet) ReadData(msg interface{})

func (*Packet) ReadEntityID

func (p *Packet) ReadEntityID() common.EntityID

func (*Packet) ReadFloat32

func (p *Packet) ReadFloat32() float32

func (*Packet) ReadFloat64

func (p *Packet) ReadFloat64() float64

func (*Packet) ReadStringList

func (p *Packet) ReadStringList() []string

func (*Packet) ReadUint16

func (p *Packet) ReadUint16() (v uint16)

func (*Packet) ReadUint32

func (p *Packet) ReadUint32() (v uint32)

func (*Packet) ReadUint64

func (p *Packet) ReadUint64() (v uint64)

func (*Packet) ReadVarBytes

func (p *Packet) ReadVarBytes() []byte

func (*Packet) ReadVarStr

func (p *Packet) ReadVarStr() string

func (*Packet) Release

func (p *Packet) Release()

func (*Packet) SetPayloadLen

func (p *Packet) SetPayloadLen(plen uint32)

type PacketConnection

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

func NewPacketConnection

func NewPacketConnection(conn Connection, compressed bool) *PacketConnection

func (*PacketConnection) Close

func (pc *PacketConnection) Close() error

func (*PacketConnection) Flush

func (pc *PacketConnection) Flush() (err error)

func (*PacketConnection) LocalAddr

func (pc *PacketConnection) LocalAddr() net.Addr

func (*PacketConnection) NewPacket

func (pc *PacketConnection) NewPacket() *Packet

func (*PacketConnection) RecvPacket

func (pc *PacketConnection) RecvPacket() (*Packet, error)

func (*PacketConnection) RemoteAddr

func (pc *PacketConnection) RemoteAddr() net.Addr

func (*PacketConnection) SendPacket

func (pc *PacketConnection) SendPacket(packet *Packet) error

func (*PacketConnection) SetRecvDeadline

func (pc *PacketConnection) SetRecvDeadline(deadline time.Time) error

func (*PacketConnection) String

func (pc *PacketConnection) String() string

type RawConnection

type RawConnection struct {
	net.Conn
}

func NewRawConnection

func NewRawConnection(conn net.Conn) RawConnection

func (RawConnection) Recv

func (rc RawConnection) Recv(buf []byte) error

func (RawConnection) Send

func (rc RawConnection) Send(data []byte) error

func (RawConnection) String

func (rc RawConnection) String() string

type SendBuffer

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

func NewSendBuffer

func NewSendBuffer() *SendBuffer

Allocate a new send buffer

func (*SendBuffer) FreeSpace

func (sb *SendBuffer) FreeSpace() int

func (*SendBuffer) Write

func (sb *SendBuffer) Write(b []byte) (n int, err error)

func (*SendBuffer) WriteTo

func (sb *SendBuffer) WriteTo(writer io.Writer) error

type TCPServerDelegate

type TCPServerDelegate interface {
	ServeTCPConnection(net.Conn)
}

Jump to

Keyboard shortcuts

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