github.com/glide-im/glide@v1.6.0/pkg/conn/tcp_conn.go (about) 1 package conn 2 3 import "net" 4 5 type TcpConnection struct { 6 c *net.TCPConn 7 } 8 9 func NewTcpConn(c *net.TCPConn) *TcpConnection { 10 return &TcpConnection{c: c} 11 } 12 13 func (t TcpConnection) Write(data []byte) error { 14 _, err := t.c.Write(data) 15 return err 16 } 17 18 func (t TcpConnection) Read() ([]byte, error) { 19 var b []byte 20 _, err := t.c.Read(b) 21 return b, err 22 } 23 24 func (t TcpConnection) Close() error { 25 return t.c.Close() 26 } 27 28 func (t TcpConnection) GetConnInfo() *ConnectionInfo { 29 addr := t.c.RemoteAddr().(*net.TCPAddr) 30 return &ConnectionInfo{ 31 Ip: addr.IP.String(), 32 Port: addr.Port, 33 Addr: t.c.RemoteAddr().String(), 34 } 35 }