1 Star 0 Fork 2

何吕 / volantmq

forked from JUMEI_ARCH / volantmq 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
connTCP.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
package transport
import (
"errors"
"net"
"os"
"time"
"github.com/VolantMQ/volantmq/systree"
)
type connTCP struct {
conn net.Conn
stat systree.BytesMetric
}
var _ conn = (*connTCP)(nil)
// NewConnTCP initiate connection with net.Conn tcp object and stat
func newConnTCP(conn net.Conn, stat systree.BytesMetric) (conn, error) {
c := &connTCP{
conn: conn,
stat: stat,
}
return c, nil
}
func (c *connTCP) Read(b []byte) (int, error) {
n, err := c.conn.Read(b)
c.stat.Received(uint64(n))
return n, err
}
func (c *connTCP) Write(b []byte) (int, error) {
n, err := c.conn.Write(b)
c.stat.Sent(uint64(n))
return n, err
}
func (c *connTCP) Close() error {
return c.conn.Close()
}
func (c *connTCP) LocalAddr() net.Addr {
return c.conn.LocalAddr()
}
func (c *connTCP) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
}
func (c *connTCP) SetDeadline(t time.Time) error {
return c.conn.SetDeadline(t)
}
func (c *connTCP) SetReadDeadline(t time.Time) error {
return c.conn.SetReadDeadline(t)
}
func (c *connTCP) SetWriteDeadline(t time.Time) error {
return c.conn.SetWriteDeadline(t)
}
func (c *connTCP) File() (*os.File, error) {
switch c.conn.(type) {
case *net.TCPConn:
return c.conn.(*net.TCPConn).File()
case *TLSConnection:
return c.conn.(*TLSConnection).File()
}
return nil, errors.New("not implemented")
}
Go
1
https://gitee.com/kaifazhe/volantmq.git
git@gitee.com:kaifazhe/volantmq.git
kaifazhe
volantmq
volantmq
v0.0.4

搜索帮助