1 Star 0 Fork 0

junqirao / links-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
io.go 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
junqirao 提交于 2022-10-23 18:14 . feat: 扩展io方法
package transmitter
import (
"net"
"time"
)
type IO struct {
rwc net.Conn
packer *packer
}
func WrapConn(conn net.Conn) *IO {
return &IO{
rwc: conn,
packer: newPacker(),
}
}
func (io *IO) ReadOnePacket() (p []byte, n int, err error) {
return io.packer.ReadOnePacket(io.rwc)
}
func (io *IO) Read(p []byte) (n int, err error) {
return io.rwc.Read(p)
}
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()
}
func (io *IO) LocalAddr() net.Addr {
return io.rwc.LocalAddr()
}
func (io *IO) RemoteAddr() net.Addr {
return io.rwc.RemoteAddr()
}
func (io *IO) SetDeadline(t time.Time) error {
return io.SetDeadline(t)
}
func (io *IO) SetReadDeadline(t time.Time) error {
return io.SetReadDeadline(t)
}
func (io *IO) SetWriteDeadline(t time.Time) error {
return io.SetWriteDeadline(t)
}
type ConcurrencyIO struct {
rwc net.Conn
packer *concurrencyPacker
}
func WrapConcurrentConn(conn net.Conn) *ConcurrencyIO {
return &ConcurrencyIO{
rwc: conn,
packer: newConcurrencyPacker(),
}
}
func (io *ConcurrencyIO) ReadOnePacket() (p []byte, n int, err error) {
return io.packer.ReadOnePacket(io.rwc)
}
func (io *ConcurrencyIO) Read(p []byte) (n int, err error) {
return io.rwc.Read(p)
}
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()
}
func (io *ConcurrencyIO) LocalAddr() net.Addr {
return io.rwc.LocalAddr()
}
func (io *ConcurrencyIO) RemoteAddr() net.Addr {
return io.rwc.RemoteAddr()
}
func (io *ConcurrencyIO) SetDeadline(t time.Time) error {
return io.SetDeadline(t)
}
func (io *ConcurrencyIO) SetReadDeadline(t time.Time) error {
return io.SetReadDeadline(t)
}
func (io *ConcurrencyIO) SetWriteDeadline(t time.Time) error {
return io.SetWriteDeadline(t)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jackrabbit872568318/links-core.git
git@gitee.com:jackrabbit872568318/links-core.git
jackrabbit872568318
links-core
links-core
v0.1.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891