qnet

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

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 = 15
)
View Source
var (
	TConnReadTimeout = 60
)
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 choykit.Endpoint) error

func NewFakeConn

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

func ReadProtoMessage added in v1.0.2

func ReadProtoMessage(conn net.Conn, cdec choykit.Codec, msgOut proto.Message) (*choykit.Packet, error)

func RequestMessage added in v1.0.2

func RequestMessage(conn net.Conn, cdec choykit.Codec, reqCommand int32, msgReq, msgResp proto.Message) error

send request message and wait for response message

func SendPacketMessage added in v1.0.2

func SendPacketMessage(conn net.Conn, cdec choykit.Codec, pkt *choykit.Packet) error

func SendProtoMessage added in v1.0.2

func SendProtoMessage(conn net.Conn, cdec choykit.Codec, command int32, msgIn proto.Message) error

Types

type ConnBase

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

func (*ConnBase) Codec added in v1.0.2

func (c *ConnBase) Codec() choykit.Codec

func (*ConnBase) Context

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

func (*ConnBase) IsClosing

func (c *ConnBase) IsClosing() bool

func (*ConnBase) NodeID

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

func (*ConnBase) RemoteAddr

func (c *ConnBase) RemoteAddr() string

func (*ConnBase) SetContext

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

func (*ConnBase) SetNodeID

func (c *ConnBase) SetNodeID(node choykit.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() *choykit.Stats

func (*ConnBase) UserData

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

type Error

type Error struct {
	Err      error
	Endpoint choykit.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(*choykit.Packet) error

type RpcContext

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

RPC上下文

func NewRpcContext

func NewRpcContext(node choykit.NodeID, 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) NodeID added in v1.0.2

func (r *RpcContext) NodeID() choykit.NodeID

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(node choykit.NodeID, request, reply int32, body proto.Message) *RpcContext

同步RPC

func (*RpcFactory) CallAsync

func (r *RpcFactory) CallAsync(node choykit.NodeID, 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 *choykit.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 choykit.NodeID, conn net.Conn, cdec choykit.Codec, errChan chan error,
	incoming chan<- *choykit.Packet, outsize int, stats *choykit.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 *choykit.Packet

func (*TcpConn) RawConn

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

func (*TcpConn) SendPacket

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

type TcpServer

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

func NewTcpServer

func NewTcpServer(cdec choykit.Codec, inbound chan *choykit.Packet, outsize int) *TcpServer

func (*TcpServer) BacklogChan

func (s *TcpServer) BacklogChan() chan choykit.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 choykit.NodeID, conn *websocket.Conn, cdec choykit.Codec, errChan chan error,
	incoming chan<- *choykit.Packet, outsize int, stats *choykit.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 *choykit.Packet) error

func (*WsConn) SendPacket

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

type WsServer

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

Websocket server

func NewWebsocketServer

func NewWebsocketServer(addr, path string, cdec choykit.Codec, inbound chan *choykit.Packet, outsize int) *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