protocol

package module
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: GPL-2.0 Imports: 11 Imported by: 0

README

Protocol

一个简易的数据传输协议,保证在流传输协议下,每次Write的数据对方能完整(不多&不少)的接收和处理

GoReport Gitea Release Go.Dev reference

import "git.viry.cc/gomod/protocol"

样例请参照protocol_test.go中的示例,示例中包含了对tcp的封装

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDataSizeExceedsLimit = errors.New("body size exceeds limit")
View Source
var ErrEncryptorIsNil = errors.New("encryptor is nil")
View Source
var ErrReaderIsNil = errors.New("reader is nil")
View Source
var ErrWriterIsKilled = errors.New("sender is killed")
View Source
var ErrWriterIsNil = errors.New("sender is nil")

Functions

This section is empty.

Types

type HeartbeatTimeoutCallback added in v0.3.0

type HeartbeatTimeoutCallback func(p *Protocol) bool

type KillCallback added in v0.3.0

type KillCallback func()

type Protocol

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

func New

func New(tag string, r io.Reader, w io.Writer, passwordAes, passwordXor string, heartbeatInterval, heartbeatTimeout uint32, sendQueueSize, receiveQueueSize int, readCallback ReadCallback, heartbeatTimeoutCallback HeartbeatTimeoutCallback, killCallback KillCallback, readPrepare ReadPrepare, writePrepare WritePrepare) (prot *Protocol, err error)

New 返回一个protocol实例

tag: 标签,用于区分protocol实例
r: 数据流的reader
w: 数据流的writer
writeQueueSize: 发送等待队列长度
readCallback: 用于处理获取到的数据,每个package中的数据都会完整的保存在data中
heartbeatTimeoutCallback: 心跳请求超时后的处理函数
setFuncBeforeRead: 在reader读取数据前,设置reader的读取截止时间
setFuncBeforeWrite: 在writer发送数据前,设置writer的发送截止时间
killCallback: status被标记为statusKilled时执行,可以用于关闭reader和writer

func (*Protocol) Connect added in v0.1.0

func (p *Protocol) Connect(activeHeartbeatSignalSender bool)

func (*Protocol) HeartbeatLastReceived added in v0.3.7

func (p *Protocol) HeartbeatLastReceived() int64

func (*Protocol) HeartbeatLastSend added in v0.3.7

func (p *Protocol) HeartbeatLastSend() int64

func (*Protocol) Kill

func (p *Protocol) Kill()

func (*Protocol) Tag added in v0.3.7

func (p *Protocol) Tag() string

func (*Protocol) Wait added in v0.3.0

func (p *Protocol) Wait()

func (*Protocol) Write

func (p *Protocol) Write(flag, encryptor uint8, data []byte) error

type ReadCallback added in v0.3.0

type ReadCallback func(data []byte)

type ReadPrepare added in v0.3.0

type ReadPrepare func()

type WritePrepare added in v0.3.0

type WritePrepare func()

Directories

Path Synopsis
pkg
xor

Jump to

Keyboard shortcuts

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