summaryrefslogtreecommitdiffhomepage
path: root/conn/bind_std.go
diff options
context:
space:
mode:
Diffstat (limited to 'conn/bind_std.go')
-rw-r--r--conn/bind_std.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/conn/bind_std.go b/conn/bind_std.go
index 5261779..cb85cfd 100644
--- a/conn/bind_std.go
+++ b/conn/bind_std.go
@@ -118,11 +118,11 @@ again:
}
var fns []ReceiveFunc
if ipv4 != nil {
- fns = append(fns, makeReceiveFunc(ipv4, true))
+ fns = append(fns, bind.makeReceiveIPv4(ipv4))
bind.ipv4 = ipv4
}
if ipv6 != nil {
- fns = append(fns, makeReceiveFunc(ipv6, false))
+ fns = append(fns, bind.makeReceiveIPv6(ipv6))
bind.ipv6 = ipv6
}
if len(fns) == 0 {
@@ -152,16 +152,23 @@ func (bind *StdNetBind) Close() error {
return err2
}
-func makeReceiveFunc(conn *net.UDPConn, isIPv4 bool) ReceiveFunc {
+func (*StdNetBind) makeReceiveIPv4(conn *net.UDPConn) ReceiveFunc {
return func(buff []byte) (int, Endpoint, error) {
n, endpoint, err := conn.ReadFromUDP(buff)
- if isIPv4 && endpoint != nil {
+ if endpoint != nil {
endpoint.IP = endpoint.IP.To4()
}
return n, (*StdNetEndpoint)(endpoint), err
}
}
+func (*StdNetBind) makeReceiveIPv6(conn *net.UDPConn) ReceiveFunc {
+ return func(buff []byte) (int, Endpoint, error) {
+ n, endpoint, err := conn.ReadFromUDP(buff)
+ return n, (*StdNetEndpoint)(endpoint), err
+ }
+}
+
func (bind *StdNetBind) Send(buff []byte, endpoint Endpoint) error {
var err error
nend, ok := endpoint.(*StdNetEndpoint)