Documentation ¶
Index ¶
- Constants
- Variables
- func HasFlags(v, flags uint32) bool
- func NewNetService(opts ...Option) *service
- func ReplayError(pkt *Packet, e error)
- type Client
- type Config
- type Conn
- type ConnCallback
- type KCPListener
- type NetName
- type NetService
- type NetWorkName
- type Option
- func WithCheckFlags(CheckFlags uint32) Option
- func WithCompressType(CompressType bbq.CompressType) Option
- func WithConnCallback(ph ConnCallback) Option
- func WithConnectionTimeout(connectionTimeout time.Duration) Option
- func WithContentType(ContentType bbq.ContentType) Option
- func WithKcpMTU(mtu int) Option
- func WithKcpNodelay(nodelay bool, intval, fr, nc int) Option
- func WithKcpSetAckNoDelay(KcpSetAckNoDelay bool) Option
- func WithKcpSetStreamMode(KcpSetStreamMode bool) Option
- func WithKcpSetWriteDelay(KcpSetWriteDelay bool) Option
- func WithMaxSendPacketSize(maxSendPacketSize int) Option
- func WithNetNoDelay(NetNoDelay bool) Option
- func WithNetwork(network NetWorkName, address string) Option
- func WithPacketHandler(ph PacketHandler) Option
- func WithReadBufferSize(readBufferSize int) Option
- func WithRequestTimeout(requestTimeout time.Duration) Option
- func WithTcpKeepAlive(NetKeepAlive bool) Option
- func WithTls(CACertFile, TLSCertFile, TLSKeyFile string) Option
- func WithWriteBufferSize(writeBufferSize int) Option
- type Options
- type Packet
- type PacketHandler
- type PacketReadWriter
- type PacketType
- type ServiceName
- type TCPListener
- type WebSocketService
Constants ¶
const (
FlagDataChecksumIEEE uint32 = 0x01
)
const MaxCloseWaitTime = 10
const (
MaxPacketBodyLength = bytespool.MaxBufferCap
)
Variables ¶
var DefaultOptions = &Options{ network: TCP, address: "", CACertFile: "", TLSCertFile: "", TLSKeyFile: "", CompressType: bbq.CompressType_None, ContentType: bbq.ContentType_Proto, CheckFlags: 0, maxSendPacketSize: 0, writeBufferSize: 0, readBufferSize: 0, connectionTimeout: 5 * time.Second, RequestTimeout: 5 * time.Second, MaxCloseWaitTime: 10, NetNoDelay: true, NetKeepAlive: true, KcpSetStreamMode: true, KcpSetWriteDelay: true, KcpSetAckNoDelay: true, KcpInternalUpdateTimerInterval: 10, KcpEnableFastResend: 2, KcpDisableCongestionControl: 1, KcpMTU: 1400, PacketHandler: nil, ConnCallback: nil, }
Functions ¶
func NewNetService ¶
func NewNetService(opts ...Option) *service
func ReplayError ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) SendPacket ¶
type Conn ¶
type Conn struct { PacketHandler PacketHandler ConnCallbacks []ConnCallback // contains filtered or unexported fields }
func (*Conn) SendPacket ¶
AsyncWritePacket async writes a packet, this method will never block
type ConnCallback ¶
type KCPListener ¶
type KCPListener struct {
// contains filtered or unexported fields
}
func NewDefaultKCPListener ¶
func NewDefaultKCPListener(opts *Options) *KCPListener
func (*KCPListener) Accept ¶
func (kl *KCPListener) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*KCPListener) Addr ¶
func (kl *KCPListener) Addr() net.Addr
Addr returns the listener's network address.
func (*KCPListener) Close ¶
func (kl *KCPListener) Close() error
Close closes the listener. Any blocked Accept operations will be unblocked and return errors.
func (*KCPListener) Listen ¶
func (kl *KCPListener) Listen(network NetWorkName, address string) (net.Listener, error)
func (*KCPListener) Name ¶
func (kl *KCPListener) Name() NetWorkName
type NetName ¶
type NetName interface { // Name returns the name of the Transport implementation. // the result cannot change between calls. Name() NetWorkName }
type NetService ¶
type NetService interface { ServiceName ListenAndServe() error Close(chan struct{}) error }
type NetWorkName ¶
type NetWorkName string
const ( WebSocket NetWorkName = "websocket" TCP NetWorkName = "tcp" TCP6 NetWorkName = "tcp6" KCP NetWorkName = "kcp" )
type Option ¶
type Option func(*Options)
A Option sets options such as credentials, codec and keepalive parameters, etc.
func WithCheckFlags ¶
func WithCompressType ¶
func WithCompressType(CompressType bbq.CompressType) Option
func WithConnCallback ¶
func WithConnCallback(ph ConnCallback) Option
func WithConnectionTimeout ¶
func WithContentType ¶
func WithContentType(ContentType bbq.ContentType) Option
func WithKcpMTU ¶
func WithKcpNodelay ¶
func WithKcpSetAckNoDelay ¶
func WithKcpSetStreamMode ¶
func WithKcpSetWriteDelay ¶
func WithMaxSendPacketSize ¶
func WithNetNoDelay ¶
func WithNetwork ¶
func WithNetwork(network NetWorkName, address string) Option
func WithPacketHandler ¶
func WithPacketHandler(ph PacketHandler) Option
func WithReadBufferSize ¶
func WithRequestTimeout ¶
func WithTcpKeepAlive ¶
func WithWriteBufferSize ¶
type Options ¶
type Options struct { CACertFile string // ca证书 TLSCertFile string // server证书 TLSKeyFile string // server秘钥 CompressType bbq.CompressType //压缩类型 ContentType bbq.ContentType //协议编码类型 CheckFlags uint32 RequestTimeout time.Duration MaxCloseWaitTime time.Duration NetNoDelay bool // for tcp NetKeepAlive bool // for kcp KcpSetStreamMode bool KcpSetWriteDelay bool KcpSetAckNoDelay bool // for kcp nodelay KcpInternalUpdateTimerInterval int KcpEnableFastResend int KcpDisableCongestionControl int // for kcp mtu KcpMTU int PacketHandler PacketHandler ConnCallback ConnCallback // contains filtered or unexported fields }
type Packet ¶
type Packet struct { Src *Conn // not nil indicates this is request packet // header: 只能在packet的生命周期内使用 Header *bbq.Header // contains filtered or unexported fields }
NOTE 如果需要通过chan 或者其他方式给其他协程使用,一定要retain,release NOTE 如果需要通过chan 或者其他方式给其他协程使用,一定要retain,release NOTE 如果需要通过chan 或者其他方式给其他协程使用,一定要retain,release Packet is a packet for sending data
func (*Packet) GetPacketCap ¶
PacketCap returns the current packetBody capacity
func (*Packet) PacketBody ¶
PacketBody returns the total packetBody of packet
type PacketHandler ¶
type PacketReadWriter ¶
type PacketReadWriter struct { Config Config // contains filtered or unexported fields }
PacketReadWriter is a connection that send and receive data packets upon a network stream connection
func NewPacketReadWriter ¶
func NewPacketReadWriter(conn *Conn) *PacketReadWriter
NewPacketReadWriter creates a packet connection based on network connection
func NewPacketReadWriterWithConfig ¶
func NewPacketReadWriterWithConfig(conn *Conn, cfg *Config) *PacketReadWriter
func (*PacketReadWriter) ReadPacket ¶
func (pc *PacketReadWriter) ReadPacket() (*Packet, error)
recv receives the next packet
type PacketType ¶
type PacketType uint8
const ( PacketRPC PacketType = 0x0 PacketSys PacketType = 0x1 )
func (PacketType) String ¶
func (t PacketType) String() string
type ServiceName ¶
type ServiceName interface { // Name returns the name of the Transport implementation. // the result cannot change between calls. Name() string }
type TCPListener ¶
type TCPListener struct {
// contains filtered or unexported fields
}
func NewTCPListener ¶
func NewTCPListener(net NetWorkName, opts *Options) *TCPListener
func (*TCPListener) Accept ¶
func (tl *TCPListener) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*TCPListener) Addr ¶
func (tl *TCPListener) Addr() net.Addr
Addr returns the listener's network address.
func (*TCPListener) Close ¶
func (tl *TCPListener) Close() error
Close closes the listener. Any blocked Accept operations will be unblocked and return errors.
func (*TCPListener) Listen ¶
func (tl *TCPListener) Listen(network NetWorkName, address string) (net.Listener, error)
func (*TCPListener) Name ¶
func (tl *TCPListener) Name() NetWorkName
type WebSocketService ¶
type WebSocketService struct {
// contains filtered or unexported fields
}
func (*WebSocketService) Close ¶
func (ws *WebSocketService) Close(chan struct{}) error
func (*WebSocketService) ListenAndServe ¶
func (ws *WebSocketService) ListenAndServe(network NetWorkName, address string, opts *Options) error
func (*WebSocketService) Name ¶
func (ws *WebSocketService) Name() NetWorkName