socket

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProactivelyCloseSocket = errors.New("socket is closed proactively")

Functions

func ReadBuffer

func ReadBuffer() (bytes int, isDefault bool)

ReadBuffer 获取链接读缓冲区长度

func SetDefaultProtoFunc

func SetDefaultProtoFunc(protoFunc ProtoFunc)

SetDefaultProtoFunc 设置默认的传输编码协议

func SetKeepAlive

func SetKeepAlive(keepalive bool)

SetKeepAlive 开启链接保活

func SetKeepAlivePeriod

func SetKeepAlivePeriod(d time.Duration)

SetKeepAlivePeriod 链接保活间隔时间

func SetNoDelay

func SetNoDelay(_noDelay bool)

SetNoDelay 开启关闭no delay算法

func SetReadBuffer

func SetReadBuffer(bytes int)

SetReadBuffer 设置链接读缓冲区长度

func SetWriteBuffer

func SetWriteBuffer(bytes int)

SetWriteBuffer 设置链接写缓冲区长度

func TryOptimize

func TryOptimize(conn net.Conn)

func WriteBuffer

func WriteBuffer() (bytes int, isDefault bool)

WriteBuffer 获取链接写缓冲区长度

Types

type HubSocket

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

HubSocket socket 仓库

func NewHubSocket

func NewHubSocket() *HubSocket

NewHubSocket 创建仓库

func (*HubSocket) ChangeID

func (that *HubSocket) ChangeID(newID string, socket Socket)

ChangeID 修改socket的id

func (*HubSocket) Delete

func (that *HubSocket) Delete(id string)

Delete 删除socket

func (*HubSocket) Get

func (that *HubSocket) Get(id string) (Socket, bool)

Get 获取socket

func (*HubSocket) Len

func (that *HubSocket) Len() int

Len 长度

func (*HubSocket) Range

func (that *HubSocket) Range(f func(Socket) bool)

Range 遍历socket

func (*HubSocket) Set

func (that *HubSocket) Set(socket Socket)

Set 添加socket

type Message

type Message = message.Message

type Proto

type Proto = proto.Proto

type ProtoFunc

type ProtoFunc = proto.ProtoFunc

func DefaultProtoFunc

func DefaultProtoFunc() ProtoFunc

DefaultProtoFunc 获取默认的传输编码协议

type Socket

type Socket interface {

	// ControlFD 获取原始句柄
	ControlFD(f func(fd uintptr)) error

	// LocalAddr 获取socket本地的地址
	LocalAddr() net.Addr

	// RemoteAddr 获取socket远端的地址
	RemoteAddr() net.Addr

	// SetDeadline 设置超时时间
	SetDeadline(t time.Time) error

	// SetReadDeadline 设置读取数据的超时时间
	SetReadDeadline(t time.Time) error

	// SetWriteDeadline 设置发送数据的超时时间
	SetWriteDeadline(t time.Time) error

	// WriteMessage 往链接中写入消息
	WriteMessage(message Message) error

	// ReadMessage 从链接中读取消息头和消息体,并填充到消息对象中
	ReadMessage(message Message) error

	// Read 从链接中读取字符
	Read(b []byte) (n int, err error)

	// Write 写入字符到链接
	Write(b []byte) (n int, err error)

	// Close 关闭链接
	Close() error

	// Swap 链接的自定义数据,如果 newSwap不为空,则会替换内部数据,并返回
	Swap(newSwap ...*dmap.Map) *dmap.Map

	// SwapLen 返回链接中自定义数据的长度
	SwapLen() int

	// ID 返回链接的id
	ID() string

	// SetID 设置链接id
	SetID(string)

	// Reset 重置net.Conn
	Reset(netConn net.Conn, protoFunc ...ProtoFunc)

	// Raw 返回原始链接
	Raw() net.Conn
}

func GetSocket

func GetSocket(c net.Conn, protoFunc ...ProtoFunc) Socket

GetSocket 获取一个socket

func NewSocket

func NewSocket(c net.Conn, protoFunc ...ProtoFunc) Socket

NewSocket 对外暴露创建链接的接口

Jump to

Keyboard shortcuts

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