client

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	StatusInitial = iota
	StatusConnecting
	StatusConnected
	StatusClosed
)

Variables

View Source
var (
	ErrInvalidStatus = errors.New("invalid client status")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*Options
	session.BaseSession
	// contains filtered or unexported fields
}

func NewClient

func NewClient(codec codec.Codec, listener session.Listener, opts ...Option) (*Client, error)

func (*Client) AsyncWrite added in v0.0.7

func (client *Client) AsyncWrite(buf []byte, callback func(c session.Conn, err error) error)

AsyncWrite

@Description: 异步写字节数组数据
@receiver client
@param buf
@param callback

func (*Client) Close

func (client *Client) Close() error

func (*Client) CloseWithContext

func (client *Client) CloseWithContext(ctx context.Context) error

func (*Client) Connection

func (client *Client) Connection() session.Conn

func (*Client) Dial

func (client *Client) Dial(ctx context.Context, address string) error

Dial

@Description: 连接
@receiver client
@param ctx
@param address 如:127.0.0.1:9999
@return error

func (*Client) IsClosed

func (client *Client) IsClosed() bool

func (*Client) SendMessage

func (client *Client) SendMessage(message any)

SendMessage

@Description: 发送消息
@receiver client
@param message

func (*Client) SendMessages

func (client *Client) SendMessages(messages ...any)

SendMessages

@Description: 发送多条消息
@receiver client
@param messages

func (*Client) Status

func (client *Client) Status() uint32

type Conn

type Conn struct {
	*net.TCPConn
	session.BaseConn
	// contains filtered or unexported fields
}

func NewConn

func NewConn(client *Client, pConn *net.TCPConn) (*Conn, error)

func (*Conn) AsyncWrite

func (conn *Conn) AsyncWrite(buf []byte, callback func(c session.Conn, err error) error) (err error)

func (*Conn) AsyncWritev

func (conn *Conn) AsyncWritev(bs [][]byte, callback func(c session.Conn, err error) error) (err error)

func (*Conn) Close

func (conn *Conn) Close() error

func (*Conn) Context

func (conn *Conn) Context() (ctx any)

func (*Conn) Discard

func (conn *Conn) Discard(n int) (discarded int, err error)

func (*Conn) Flush

func (conn *Conn) Flush() (err error)

func (*Conn) InboundBuffered

func (conn *Conn) InboundBuffered() (n int)

func (*Conn) Init

func (conn *Conn) Init(client *Client, pConn *net.TCPConn) error

func (*Conn) Next

func (conn *Conn) Next(n int) (buf []byte, err error)

func (*Conn) OutboundBuffered

func (conn *Conn) OutboundBuffered() (n int)

func (*Conn) Peek

func (conn *Conn) Peek(n int) (buf []byte, err error)

func (*Conn) Read

func (conn *Conn) Read(b []byte) (n int, err error)

func (*Conn) ReadFrom

func (conn *Conn) ReadFrom(r io.Reader) (n int64, err error)

func (*Conn) SetContext

func (conn *Conn) SetContext(_ interface{})

func (*Conn) ToClosed

func (conn *Conn) ToClosed(reason error) bool

func (*Conn) Write

func (conn *Conn) Write(b []byte) (n int, err error)

func (*Conn) WriteTo

func (conn *Conn) WriteTo(w io.Writer) (n int64, err error)

func (*Conn) Writev

func (conn *Conn) Writev(bs [][]byte) (n int, err error)

type Option

type Option func(*Options)

func WithName

func WithName(value string) Option

func WithReadBufferCap

func WithReadBufferCap(cap int) Option

func WithSocketRecvBuffer

func WithSocketRecvBuffer(cap int) Option

func WithSocketSendBuffer

func WithSocketSendBuffer(cap int) Option

func WithTCPKeepAlive

func WithTCPKeepAlive(value time.Duration) Option

func WithTCPNoDelay

func WithTCPNoDelay(value bool) Option

func WithWriteBufferCap

func WithWriteBufferCap(cap int) Option

func WithWriteQueueCap

func WithWriteQueueCap(cap int) Option

type Options

type Options struct {
	Name string
	// 读缓冲容量
	ReadBufferCap int
	// 写缓冲容量
	WriteBufferCap int
	// 同时提交写队列上限,队列满时异步写直接返回错误
	WriteQueueCap int
	// 保活时间
	TCPKeepAlive time.Duration
	// TCPNoDelay controls whether the operating system should delay
	// packet transmission in hopes of sending fewer packets (Nagle's algorithm).
	TCPNoDelay bool
	// socket读缓冲区
	SocketRecvBuffer int
	// socket写缓冲区
	SocketSendBuffer int
}

Jump to

Keyboard shortcuts

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