forked from cryptix/goSam
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdatagram.go
61 lines (55 loc) · 1.33 KB
/
datagram.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
49
50
51
52
53
54
55
56
57
58
59
60
61
package gosam
import (
"net"
"time"
)
// DatagramConn
type DatagramConn struct {
RWC
conn net.PacketConn
RAddr net.Addr
}
// WrapConn wraps a net.PacketConn in a DatagramConn.
func WrapPacketConn(c net.Conn) *Conn {
wrap := Conn{
conn: c,
}
wrap.Reader = NewReadLogger("<", c)
wrap.Writer = NewWriteLogger(">", c)
wrap.RWC.c = c
return &wrap
}
func (d *DatagramConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
return d.conn.ReadFrom(p)
}
func (d *DatagramConn) Read(b []byte) (n int, err error) {
n, _, err = d.ReadFrom(b)
return n, err
}
func (d *DatagramConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return d.conn.WriteTo(p, addr)
}
func (d *DatagramConn) Write(b []byte) (n int, err error) {
n, err = d.WriteTo(b, d.RemoteAddr())
return n, err
}
func (d *DatagramConn) Close() error {
return d.conn.Close()
}
func (d *DatagramConn) LocalAddr() net.Addr {
return d.conn.LocalAddr()
}
func (d *DatagramConn) RemoteAddr() net.Addr {
return d.RAddr
}
func (d *DatagramConn) SetDeadline(t time.Time) error {
return d.conn.SetDeadline(t)
}
func (d *DatagramConn) SetReadDeadline(t time.Time) error {
return d.conn.SetReadDeadline(t)
}
func (d *DatagramConn) SetWriteDeadline(t time.Time) error {
return d.conn.SetWriteDeadline(t)
}
var dgt net.PacketConn = &DatagramConn{}
//func (c *Client) DatagramSend()