1 Star 0 Fork 0

Bin/kir

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
reader.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
bin you 提交于 2024-09-22 00:02 . op
package main
import (
"io"
)
type monitoredReader struct {
r io.Reader
direction string
conn *monitoredConnection
// buffer []byte // 添加缓冲区
// mu sync.Mutex
}
func newMonitoredReader(r io.Reader, direction string, conn *monitoredConnection) *monitoredReader {
mr := &monitoredReader{
r: r,
direction: direction,
conn: conn,
// buffer: make([]byte, 0), // 初始化缓冲区
}
// 启动一个 Goroutine 来处理数据
// go mr.processData()
return mr
}
func (mr *monitoredReader) Read(p []byte) (n int, err error) {
n, err = mr.r.Read(p)
if n > 0 {
remainingBytes := n
for remainingBytes > 0 {
buffer := bufferPool.Get().([]byte)
copySize := min(bufferSize, remainingBytes)
copy(buffer[:copySize], p[n-remainingBytes:])
if mr.direction == "MySQL到代理" {
mr.conn.recvChannel <- buffer[:copySize]
} else if mr.direction == "客户端到代理" {
mr.conn.sendChannel <- buffer[:copySize]
}
remainingBytes -= copySize
}
// data := make([]byte, n)
// copy(data, p[:n])
// if mr.direction == "MySQL到代理" {
// mr.conn.recvChannel <- data
// } else if mr.direction == "客户端到代理" {
// mr.conn.sendChannel <- data
// }
// 将读取到的数据发送到数据通道
// mr.packetChan <- append([]byte{}, p[:n]...)
// mu.Lock()
// defer mu.Unlock()
// // mr.mu.Lock()
// defer mr.mu.Unlock()
// mr.buffer = append(mr.buffer, p[:n]...)
// mr.parseBuffer()
}
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/llyb120/kir.git
[email protected]:llyb120/kir.git
llyb120
kir
kir
master

搜索帮助