1 Star 0 Fork 0

junqirao/links-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
io.go 953 Bytes
一键复制 编辑 原始数据 按行查看 历史
junqirao 提交于 2022-10-07 09:48 . feat: 支持并发的io模型
package transmitter
import "io"
type IO struct {
rwc io.ReadWriteCloser
packer *packer
}
func WrapConn(conn io.ReadWriteCloser) *IO {
return &IO{
rwc: conn,
packer: newPacker(),
}
}
func (io *IO) Read() (p []byte, n int, err error) {
return io.packer.ReadOnePacket(io.rwc)
}
func (io *IO) Write(p []byte) (n int, err error) {
return io.rwc.Write(io.packer.Pack(p))
}
func (io *IO) Close() error {
return io.rwc.Close()
}
type ConcurrencyIO struct {
rwc io.ReadWriteCloser
packer *concurrencyPacker
}
func WrapConcurrentConn(conn io.ReadWriteCloser) *ConcurrencyIO {
return &ConcurrencyIO{
rwc: conn,
packer: newConcurrencyPacker(),
}
}
func (io *ConcurrencyIO) Read() (p []byte, n int, err error) {
return io.packer.ReadOnePacket(io.rwc)
}
func (io *ConcurrencyIO) Write(p []byte) (n int, err error) {
return io.rwc.Write(io.packer.Pack(p))
}
func (io *ConcurrencyIO) Close() error {
return io.rwc.Close()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jackrabbit872568318/links-core.git
git@gitee.com:jackrabbit872568318/links-core.git
jackrabbit872568318
links-core
links-core
v0.0.2

搜索帮助