qnet

package
v1.1.2 Latest Latest
Warning

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

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

README

qnet

网络通信处理

TCP和Websocket通信的实现

Documentation

Index

Constants

View Source
const (
	StatBytesRecv   int = iota // bytes received
	StatBytesSent              // bytes sent
	StatPacketsRecv            // packets received
	StatPacketsSent            // packets sent
	NumStat
)
View Source
const (
	WSCONN_MAX_PAYLOAD = 16 * 1024 // 16k
)

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 (
	RequestReadTimeout = 60
)
View Source
var (
	TConnReadTimeout = 100
)
View Source
var (
	WSConnReadTimeout = 100 * time.Second
)

Functions

func DialTCP added in v1.0.2

func DialTCP(address string) (*net.TCPConn, error)

func ListenTCP added in v1.0.2

func ListenTCP(address string) (*net.TCPListener, error)

func NewError

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

func NewFakeConn

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

func ReadPacketMessage added in v1.0.5

func ReadPacketMessage(conn net.Conn, decoder fatchoy.ProtocolDecoder, decrypt cipher.BlockCryptor,
	pkt *fatchoy.Packet) error

recv一个packet

func ReadProtoMessage added in v1.0.2

func ReadProtoMessage(conn net.Conn, decoder fatchoy.ProtocolDecoder, decrypt cipher.BlockCryptor,
	pkt *fatchoy.Packet, pbMsg proto.Message) error

recv一条protobuf消息

func RequestMessage added in v1.0.2

func RequestMessage(conn net.Conn, encoder fatchoy.ProtocolCodec, encrypt cipher.BlockCryptor,
	reqCommand int32, msgReq, msgResp proto.Message) error

send并且立即等待recv

func SendPacketMessage added in v1.0.2

func SendPacketMessage(conn net.Conn, encoder fatchoy.ProtocolEncoder, encrypt cipher.BlockCryptor,
	pkt *fatchoy.Packet) error

send一个packet

func SendProtoMessage added in v1.0.2

func SendProtoMessage(conn net.Conn, encoder fatchoy.ProtocolCodec, encrypt cipher.BlockCryptor,
	command int32, outMsg proto.Message) error

send一条protobuf消息

Types

type ConnBase

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

TcpConn和WsConn的公共基类

func (*ConnBase) Context

func (c *ConnBase) Context() *fatchoy.ServiceContext

func (*ConnBase) Encoder

func (c *ConnBase) Encoder() fatchoy.ProtocolCodec

func (*ConnBase) IsClosing

func (c *ConnBase) IsClosing() bool

func (*ConnBase) NodeID

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

func (*ConnBase) RemoteAddr

func (c *ConnBase) RemoteAddr() string

func (*ConnBase) SetContext

func (c *ConnBase) SetContext(v *fatchoy.ServiceContext)

func (*ConnBase) SetNodeID

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

func (*ConnBase) SetRemoteAddr

func (c *ConnBase) SetRemoteAddr(addr string)

func (*ConnBase) SetUserData

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

func (*ConnBase) Stats

func (c *ConnBase) Stats() *fatchoy.Stats

func (*ConnBase) UserData

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

type Error

type Error struct {
	Err      error
	Endpoint fatchoy.Endpoint
}

func (Error) Error

func (e Error) Error() string

type FakeConn

type FakeConn struct {
	ConnBase
}

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(bool, bool)

func (*FakeConn) RawConn

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

func (*FakeConn) SendPacket

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

type RpcContext

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

RPC上下文

func NewRpcContext

func NewRpcContext(request, reply int32, body interface{}, handler RpcHandler) *RpcContext

func (*RpcContext) Body

func (r *RpcContext) Body() interface{}

func (*RpcContext) DecodeMsg

func (r *RpcContext) DecodeMsg(v proto.Message) error

func (*RpcContext) Done

func (r *RpcContext) Done(ec uint32, body interface{})

func (*RpcContext) Errno

func (r *RpcContext) Errno() uint32

func (*RpcContext) Run

func (r *RpcContext) Run() error

func (*RpcContext) Succeed

func (r *RpcContext) Succeed() bool

type RpcFactory

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

RPC工厂

func (*RpcFactory) Call

func (r *RpcFactory) Call(request, reply int32, body proto.Message) *RpcContext

同步RPC

func (*RpcFactory) CallAsync

func (r *RpcFactory) CallAsync(request, reply int32, body proto.Message, cb RpcHandler) *RpcContext

异步RPC

func (*RpcFactory) Go

func (r *RpcFactory) Go()

func (*RpcFactory) Init

func (r *RpcFactory) Init(ctx *fatchoy.ServiceContext) error

func (*RpcFactory) Shutdown

func (r *RpcFactory) Shutdown()

type RpcHandler

type RpcHandler func(*RpcContext) error

type TcpConn

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

TCP connection

func NewTcpConn

func NewTcpConn(node fatchoy.NodeID, conn net.Conn, encoder fatchoy.ProtocolCodec, errChan chan error,
	incoming chan<- *fatchoy.Packet, outsize int32, stats *fatchoy.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(writer, reader bool)

func (*TcpConn) OutboundQueue

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

func (*TcpConn) RawConn

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

func (*TcpConn) SendPacket

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

type TcpServer

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

func NewTcpServer

func NewTcpServer(encoder fatchoy.ProtocolCodec, inbound chan *fatchoy.Packet, outsize int32) *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()

type WsConn

type WsConn struct {
	ConnBase
	// contains filtered or unexported fields
}

Websocket connection

func NewWsConn

func NewWsConn(node fatchoy.NodeID, conn *websocket.Conn, encoder fatchoy.ProtocolCodec, errChan chan error,
	incoming chan<- *fatchoy.Packet, outsize int32, stats *fatchoy.Stats) *WsConn

func (*WsConn) Close

func (c *WsConn) Close() error

func (*WsConn) ForceClose

func (c *WsConn) ForceClose(err error)

func (*WsConn) Go

func (c *WsConn) Go(writer, reader bool)

func (*WsConn) RawConn

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

func (*WsConn) ReadPacket added in v0.2.2

func (c *WsConn) ReadPacket(pkt *fatchoy.Packet) error

func (*WsConn) SendPacket

func (c *WsConn) SendPacket(pkt *fatchoy.Packet) error

type WsServer

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

Websocket server

func NewWebsocketServer

func NewWebsocketServer(addr, path string, encoder fatchoy.ProtocolCodec, inbound chan *fatchoy.Packet, outsize int32) *WsServer

func (*WsServer) BacklogChan

func (s *WsServer) BacklogChan() chan *WsConn

func (*WsServer) ErrChan

func (s *WsServer) ErrChan() chan error

func (*WsServer) Go

func (s *WsServer) Go()

func (*WsServer) Shutdown

func (s *WsServer) Shutdown()

Jump to

Keyboard shortcuts

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