qnet

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatBytesRecv   int = iota // bytes received
	StatBytesSent              // bytes sent
	StatPacketsRecv            // packets received
	StatPacketsSent            // packets sent
	NumStat
)

Variables

View Source
var (
	ErrConnIsClosing        = errors.New("connection is closing when sending")
	ErrConnOutboundOverflow = errors.New("connection outbound queue overflow")
	ErrConnForceClose       = errors.New("connection forced to close")
)
View Source
var ErrBufferOutOfRange = errors.New("buffer out of range")
View Source
var (
	RequestReadTimeout = 100 // 默认read超时时间,100s
)
View Source
var (
	TConnReadTimeout = 200
)

Functions

func NewFakeConn

func NewFakeConn(node fatchoy.NodeID, addr string) fatchoy.Endpoint

func ReadLenMessage added in v0.1.5

func ReadLenMessage(conn net.Conn, msg proto.Message) error

读取2字节开头的message

func ReadProtoMessage added in v0.1.12

func ReadProtoMessage(conn net.Conn, enc codec.Encoder, decrypt cipher.BlockCryptor, pkt fatchoy.IPacket, msg proto.Message) error

读取一条消息

func RequestLenMessage added in v0.1.5

func RequestLenMessage(conn net.Conn, req, ack proto.Message) error

写入req并且等待读取ack

func RequestProtoMessage added in v0.1.12

func RequestProtoMessage(conn net.Conn, enc codec.Encoder, command int32, req, resp proto.Message) error

send并且立即等待recv(不加密)

func SendProtoMessage added in v0.1.12

func SendProtoMessage(conn io.Writer, enc codec.Encoder, encrypt cipher.BlockCryptor, command int32, msg proto.Message) error

send一条protobuf消息

func WriteLenMessage added in v0.1.5

func WriteLenMessage(conn net.Conn, msg proto.Message) error

写入2字节开头的message

Types

type Buffer

type Buffer struct {
	bytes.Buffer
}

func (*Buffer) PeekBool

func (b *Buffer) PeekBool() bool

func (*Buffer) PeekFloat32

func (b *Buffer) PeekFloat32() float32

func (*Buffer) PeekFloat64

func (b *Buffer) PeekFloat64() float64

func (*Buffer) PeekInt

func (b *Buffer) PeekInt() int

func (*Buffer) PeekInt16

func (b *Buffer) PeekInt16() int16

func (*Buffer) PeekInt32

func (b *Buffer) PeekInt32() int32

func (*Buffer) PeekInt64

func (b *Buffer) PeekInt64() int64

func (*Buffer) PeekInt8

func (b *Buffer) PeekInt8() int8

func (*Buffer) PeekUint

func (b *Buffer) PeekUint() uint

func (*Buffer) PeekUint16

func (b *Buffer) PeekUint16() uint16

func (*Buffer) PeekUint32

func (b *Buffer) PeekUint32() uint32

func (*Buffer) PeekUint64

func (b *Buffer) PeekUint64() uint64

func (*Buffer) PeekUint8

func (b *Buffer) PeekUint8() uint8

func (*Buffer) ReadBool

func (b *Buffer) ReadBool() bool

func (*Buffer) ReadFloat32

func (b *Buffer) ReadFloat32() float32

func (*Buffer) ReadFloat64

func (b *Buffer) ReadFloat64() float64

func (*Buffer) ReadInt

func (b *Buffer) ReadInt() int

func (*Buffer) ReadInt16

func (b *Buffer) ReadInt16() int16

func (*Buffer) ReadInt32

func (b *Buffer) ReadInt32() int32

func (*Buffer) ReadInt64

func (b *Buffer) ReadInt64() int64

func (*Buffer) ReadInt8

func (b *Buffer) ReadInt8() int8

func (*Buffer) ReadUint

func (b *Buffer) ReadUint() uint

func (*Buffer) ReadUint16

func (b *Buffer) ReadUint16() uint16

func (*Buffer) ReadUint32

func (b *Buffer) ReadUint32() uint32

func (*Buffer) ReadUint64

func (b *Buffer) ReadUint64() uint64

func (*Buffer) ReadUint8

func (b *Buffer) ReadUint8() uint8

func (*Buffer) WriteBool

func (b *Buffer) WriteBool(v bool)

func (*Buffer) WriteFloat32

func (b *Buffer) WriteFloat32(f float32)

func (*Buffer) WriteFloat64

func (b *Buffer) WriteFloat64(f float64)

func (*Buffer) WriteInt

func (b *Buffer) WriteInt(n int)

func (*Buffer) WriteInt16

func (b *Buffer) WriteInt16(n int16)

func (*Buffer) WriteInt32

func (b *Buffer) WriteInt32(n int32)

func (*Buffer) WriteInt64

func (b *Buffer) WriteInt64(n int64)

func (*Buffer) WriteInt8

func (b *Buffer) WriteInt8(n int8)

func (*Buffer) WriteUInt8

func (b *Buffer) WriteUInt8(n uint8)

func (*Buffer) WriteUint

func (b *Buffer) WriteUint(n uint)

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(n uint16)

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(n uint32)

func (*Buffer) WriteUint64

func (b *Buffer) WriteUint64(n uint64)

type Error

type Error struct {
	Err      error
	Endpoint fatchoy.Endpoint
}

func NewError

func NewError(err error, endpoint fatchoy.Endpoint) *Error

func (Error) Error

func (e Error) Error() string

type FakeConn

type FakeConn struct {
	StreamConn
}

a fake endpoint

func (*FakeConn) Close

func (c *FakeConn) Close() error

func (*FakeConn) ForceClose

func (c *FakeConn) ForceClose(error)

func (*FakeConn) Go

func (c *FakeConn) Go(flag fatchoy.EndpointFlag)

func (*FakeConn) RawConn

func (c *FakeConn) RawConn() net.Conn

func (*FakeConn) SendPacket

func (c *FakeConn) SendPacket(fatchoy.IPacket) error

type RpcClient added in v0.1.5

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

RPC client stub

func NewRpcClient added in v0.1.5

func NewRpcClient(queueSize int) *RpcClient

func (*RpcClient) AsyncCall added in v0.1.5

func (c *RpcClient) AsyncCall(node fatchoy.NodeID, req proto.Message, cb RpcHandler) error

func (*RpcClient) Call added in v0.1.5

func (c *RpcClient) Call(node fatchoy.NodeID, req proto.Message) *RpcContext

func (*RpcClient) Dispatch added in v0.1.5

func (c *RpcClient) Dispatch(pkt fatchoy.IPacket) error

在主线程运行

func (*RpcClient) IsRunning added in v0.1.23

func (c *RpcClient) IsRunning() bool

func (*RpcClient) PendingQueue added in v0.1.5

func (c *RpcClient) PendingQueue() <-chan fatchoy.IPacket

func (*RpcClient) ReapTimeout added in v0.1.5

func (c *RpcClient) ReapTimeout() int

func (*RpcClient) Shutdown added in v0.1.23

func (c *RpcClient) Shutdown()

func (*RpcClient) Start added in v0.1.23

func (c *RpcClient) Start()

type RpcContext added in v0.1.5

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

RPC上下文

func NewRpcContext added in v0.1.5

func NewRpcContext(node fatchoy.NodeID, req proto.Message, action RpcHandler) *RpcContext

func (*RpcContext) DecodeAck added in v0.1.5

func (r *RpcContext) DecodeAck() (proto.Message, error)

type RpcHandler added in v0.1.5

type RpcHandler func(proto.Message, int32) error

type StreamConn

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

stream connection

func (*StreamConn) Init added in v0.1.14

func (c *StreamConn) Init(node fatchoy.NodeID, enc codec.Encoder, inbound chan<- fatchoy.IPacket,
	outsize int, errChan chan error, stat *stats.Stats)

func (*StreamConn) IsRunning added in v0.1.20

func (c *StreamConn) IsRunning() bool

func (*StreamConn) NodeID

func (c *StreamConn) NodeID() fatchoy.NodeID

func (*StreamConn) RemoteAddr

func (c *StreamConn) RemoteAddr() string

func (*StreamConn) SetEncryptPair

func (c *StreamConn) SetEncryptPair(encrypt cipher.BlockCryptor, decrypt cipher.BlockCryptor)

func (*StreamConn) SetNodeID

func (c *StreamConn) SetNodeID(node fatchoy.NodeID)

func (*StreamConn) SetRemoteAddr

func (c *StreamConn) SetRemoteAddr(addr string)

func (*StreamConn) SetUserData

func (c *StreamConn) SetUserData(ud interface{})

func (*StreamConn) Stats

func (c *StreamConn) Stats() *stats.Stats

func (*StreamConn) UserData

func (c *StreamConn) UserData() interface{}

type TcpConn

type TcpConn struct {
	StreamConn
	// contains filtered or unexported fields
}

TCP connection

func NewTcpConn

func NewTcpConn(node fatchoy.NodeID, conn net.Conn, enc codec.Encoder, errChan chan error,
	incoming chan<- fatchoy.IPacket, outsize int, stats *stats.Stats) *TcpConn

func (*TcpConn) Close

func (t *TcpConn) Close() error

func (*TcpConn) ForceClose

func (t *TcpConn) ForceClose(err error)

func (*TcpConn) Go

func (t *TcpConn) Go(flag fatchoy.EndpointFlag)

func (*TcpConn) OutboundQueue

func (t *TcpConn) OutboundQueue() chan fatchoy.IPacket

func (*TcpConn) RawConn

func (t *TcpConn) RawConn() net.Conn

func (*TcpConn) SendPacket

func (t *TcpConn) SendPacket(pkt fatchoy.IPacket) error

type TcpServer

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

func NewTcpServer

func NewTcpServer(enc codec.Encoder, inbound chan fatchoy.IPacket, outsize int) *TcpServer

func (*TcpServer) BacklogChan

func (s *TcpServer) BacklogChan() chan fatchoy.Endpoint

func (*TcpServer) Close

func (s *TcpServer) Close()

func (*TcpServer) ErrorChan

func (s *TcpServer) ErrorChan() chan error

func (*TcpServer) Listen

func (s *TcpServer) Listen(addr string) error

func (*TcpServer) Shutdown

func (s *TcpServer) Shutdown()

Jump to

Keyboard shortcuts

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