comm

package module
v0.0.0-...-3f44590 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 12 Imported by: 4

README

comm

Message communication SDK base on golang

性能测试

测试环境

CPU: Intel(R)Core(TM)m3-6y30 CPU@ 0.9GHz 1.51GHz
RAM: 4GB

测试数据
消息长度 吞吐量
(单位:ktps)
流量
(MB/s)
8 1189 9.408
16 1042 16.549
32 962 30.522
64 836 53.008
128 737 93.288
256 544 137.22
512 296 148.663
1024 135 136.198
2048 72 145.229
4096 41 164.289
8192 22 178.633
16384 13 216.891
32768 9 297.125

Documentation

Index

Constants

View Source
const (
	MAX_BUF_SIZE = 128 * 1024 // 缓冲区大小(单位:byte)
	MAGIC_FLAG   = 0x98b7f30a // 校验魔术字
	MSG_HEAD_LEN = 3 * 4      // 消息头长度
)

Variables

This section is empty.

Functions

func BinaryCoder

func BinaryCoder(req interface{}) ([]byte, error)

序列化操作(结构体类型)

func BinaryDecoder

func BinaryDecoder(buf []byte, rsp interface{}) error

反序列化操作(结构体类型)

func GetUint32

func GetUint32(body []byte) uint32

反序列化操作(uint32)

func GetUint64

func GetUint64(body []byte) uint64

反序列化操作(uint64)

func NewConnect

func NewConnect(conn net.Conn, buflen int) *connect

申请链路操作资源

func PutUint32

func PutUint32(value uint32, body []byte)

序列化操作(uint32)

func PutUint64

func PutUint64(value uint64, body []byte)

序列化操作(uint64)

Types

type Client

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

客户端实例的数据结构

func NewClient

func NewClient(addr string) *Client

申请客户端实例

func (*Client) RegHandler

func (c *Client) RegHandler(reqid uint32, fun ClientHandler) error

注册客户端消息处理函数

func (*Client) SendMsg

func (c *Client) SendMsg(reqid uint32, body []byte) error

发送消息结构

func (*Client) Start

func (c *Client) Start(num, buflen int) error

启动客户端处理

func (*Client) Stop

func (c *Client) Stop()

主动发起资源销毁

func (*Client) TlsEnable

func (c *Client) TlsEnable(ca, cert, key string) error

func (*Client) Wait

func (c *Client) Wait()

等待client端资源销毁

type ClientHandler

type ClientHandler func(c *Client, reqid uint32, body []byte)

客户端消息处理函数类型

type Header struct {
	ReqID uint32 // 请求ID
	Body  []byte // 传输内容
}

消息头

type Listen

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

服务端监听资源结构

func NewListen

func NewListen(addr string) *Listen

监听地址

func (*Listen) Accept

func (l *Listen) Accept() (*Server, error)

分配一个服务端实例

func (*Listen) TlsEnable

func (l *Listen) TlsEnable(ca, cert, key string) error

type Server

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

server端控制结构

func (*Server) RegHandler

func (s *Server) RegHandler(reqid uint32, fun ServerHandler) error

注册消息处理函数

func (*Server) SendMsg

func (s *Server) SendMsg(reqid uint32, body []byte) error

发送消息

func (*Server) Start

func (s *Server) Start(num, buflen int) error

启动消息处理任务

func (*Server) Stop

func (s *Server) Stop()

主动停止服务端处理

func (*Server) Wait

func (s *Server) Wait()

等待资源销毁

type ServerHandler

type ServerHandler func(*Server, uint32, []byte)

服务端消息处理函数

type Stat

type Stat struct {
	RecvCnt  int // 接收统计计数
	SendCnt  int // 发送统计计数
	ErrCnt   int // 错误统计计数
	RecvSize int // 发送大小计数(单位:byte)
	SendSize int // 接收大小计数(单位:byte)
}

func (*Stat) Add

func (s1 *Stat) Add(s2 Stat) Stat

两个统计之和

func (*Stat) AddCnt

func (s1 *Stat) AddCnt(send, recv, err int) Stat

发送、接收、错误;计数统计接口

func (*Stat) AddSize

func (s1 *Stat) AddSize(sendsize, recvsize int) Stat

size统计接口

func (*Stat) Sub

func (s1 *Stat) Sub(s2 Stat) Stat

两个统计差值

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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