-
Notifications
You must be signed in to change notification settings - Fork 3
/
connection.go
48 lines (39 loc) · 1.09 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package libzt
import (
"net"
"time"
"syscall"
"errors"
"fmt"
)
type Connection struct {
fd int
localIP net.IP
localPort uint16
remoteIp net.IP
remotePort uint16
}
func (c *Connection) Read(b []byte) (n int, err error) {
return syscall.Read(c.fd, b)
}
func (c *Connection) Write(b []byte) (n int, err error) {
return syscall.Write(c.fd, b)
}
func (c *Connection) Close() error {
val := close(c.fd)
if val < 0 {
return errors.New("Error closing socket")
}
return nil
}
func (c *Connection) LocalAddr() net.Addr {
addr, _ := net.ResolveTCPAddr("tcp6", fmt.Sprintf("[%s]:%d", c.localIP.String(), c.localPort))
return addr
}
func (c *Connection) RemoteAddr() net.Addr {
addr, _ := net.ResolveTCPAddr("tcp6", fmt.Sprintf("[%s]:%d", c.remoteIp.String(), c.remotePort))
return addr
}
func (c *Connection) SetDeadline(time.Time) error { return errors.New("Not yet supported") }
func (c *Connection) SetReadDeadline(time.Time) error { return errors.New("Not yet supported") }
func (c *Connection) SetWriteDeadline(time.Time) error { return errors.New("Not yet supported") }