1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-04 02:54:20 -04:00
v2fly/transport/hub/connection.go

67 lines
1.2 KiB
Go
Raw Normal View History

2016-04-27 17:01:31 -04:00
package hub
import (
"net"
"time"
)
2016-05-02 17:53:16 -04:00
type ConnectionHandler func(*Connection)
2016-04-27 17:01:31 -04:00
2016-05-02 17:53:16 -04:00
type Connection struct {
conn net.Conn
2016-04-27 17:01:31 -04:00
listener *TCPHub
}
2016-05-02 17:53:16 -04:00
func (this *Connection) Read(b []byte) (int, error) {
2016-04-27 17:01:31 -04:00
if this == nil || this.conn == nil {
return 0, ErrorClosedConnection
}
return this.conn.Read(b)
}
2016-05-02 17:53:16 -04:00
func (this *Connection) Write(b []byte) (int, error) {
2016-04-27 17:01:31 -04:00
if this == nil || this.conn == nil {
return 0, ErrorClosedConnection
}
return this.conn.Write(b)
}
2016-05-02 17:53:16 -04:00
func (this *Connection) Close() error {
2016-04-27 17:01:31 -04:00
if this == nil || this.conn == nil {
return ErrorClosedConnection
}
err := this.conn.Close()
return err
}
2016-05-02 17:53:16 -04:00
func (this *Connection) Release() {
2016-04-27 17:01:31 -04:00
if this == nil || this.listener == nil {
return
}
this.Close()
this.conn = nil
this.listener = nil
}
2016-05-02 17:53:16 -04:00
func (this *Connection) LocalAddr() net.Addr {
2016-04-27 17:01:31 -04:00
return this.conn.LocalAddr()
}
2016-05-02 17:53:16 -04:00
func (this *Connection) RemoteAddr() net.Addr {
2016-04-27 17:01:31 -04:00
return this.conn.RemoteAddr()
}
2016-05-02 17:53:16 -04:00
func (this *Connection) SetDeadline(t time.Time) error {
2016-04-27 17:01:31 -04:00
return this.conn.SetDeadline(t)
}
2016-05-02 17:53:16 -04:00
func (this *Connection) SetReadDeadline(t time.Time) error {
2016-04-27 17:01:31 -04:00
return this.conn.SetReadDeadline(t)
}
2016-05-02 17:53:16 -04:00
func (this *Connection) SetWriteDeadline(t time.Time) error {
2016-04-27 17:01:31 -04:00
return this.conn.SetWriteDeadline(t)
}