1 Star 0 Fork 0

wuzpdev/goworld

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BufferedConnection.go 973 Bytes
一键复制 编辑 原始数据 按行查看 历史
seis 提交于 2017-09-14 14:18 . compressed connection works?
package netutil
import (
"bufio"
"github.com/xiaonanln/goworld/engine/consts"
)
// BufferedConnection provides buffered write to connections
type BufferedConnection struct {
Connection
bufReader *bufio.Reader
bufWriter *bufio.Writer
}
// NewBufferedWriteConnection creates a new connection with buffered write based on underlying connection
func NewBufferedConnection(conn Connection) *BufferedConnection {
brc := &BufferedConnection{
Connection: conn,
}
brc.bufReader = bufio.NewReaderSize(conn, consts.BUFFERED_READ_BUFFSIZE)
brc.bufWriter = bufio.NewWriterSize(conn, consts.BUFFERED_WRITE_BUFFSIZE)
return brc
}
// Read
func (brc *BufferedConnection) Read(p []byte) (int, error) {
return brc.bufReader.Read(p)
}
func (brc *BufferedConnection) Write(p []byte) (int, error) {
return brc.bufWriter.Write(p)
}
func (brc *BufferedConnection) Flush() error {
err := brc.bufWriter.Flush()
if err != nil {
return err
}
return brc.Connection.Flush()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385