1 Star 0 Fork 0

jmesyan/impetus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tcp_conn.go 879 Bytes
一键复制 编辑 原始数据 按行查看 历史
jmesyan 提交于 2020-12-12 22:03 . init
package network
import (
"bytes"
"io"
"net"
"sync"
)
type ConnSet map[net.Conn]struct{}
type TCPConn struct {
sync.Mutex
conn net.Conn
}
func newTCPConn(conn net.Conn) *TCPConn {
tcpConn := new(TCPConn)
tcpConn.conn = conn
return tcpConn
}
func (tcpConn *TCPConn) Close() {
tcpConn.Lock()
defer tcpConn.Unlock()
tcpConn.conn.(*net.TCPConn).SetLinger(0)
tcpConn.conn.Close()
}
func (tcpConn *TCPConn) LocalAddr() net.Addr {
return tcpConn.conn.LocalAddr()
}
func (tcpConn *TCPConn) RemoteAddr() net.Addr {
return tcpConn.conn.RemoteAddr()
}
// Read buffer length data
func (tcpConn *TCPConn) Read(buffer []byte) (int, error) {
return io.ReadFull(tcpConn.conn, buffer)
}
func (tcpConn *TCPConn) ReadMsg(buf *bytes.Buffer) error {
return nil
}
func (tcpConn *TCPConn) WriteMessage(buf []byte) error {
_, err := tcpConn.conn.Write(buf)
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jmesyan/impetus.git
git@gitee.com:jmesyan/impetus.git
jmesyan
impetus
impetus
v1.1.1

搜索帮助