FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
net: make LocalAddr on multicast UDPConn return a listening address

The package go.net/ipv4 allows to exist a single UDP listener
that join multiple different group addresses. That means that
LocalAddr on multicast UDPConn returns a first joined group
address is not desirable.

Please review this at http://codereview.appspot.com/6822108/

Affected files:
M src/pkg/net/multicast_posix_test.go
M src/pkg/net/sock_posix.go


Index: src/pkg/net/multicast_posix_test.go
===================================================================
--- a/src/pkg/net/multicast_posix_test.go
+++ b/src/pkg/net/multicast_posix_test.go
@@ -120,14 +120,22 @@
if !multicastRIBContains(t, gaddr.IP) {
t.Fatalf("%q not found in RIB", gaddr.String())
}
- if c.LocalAddr().String() != gaddr.String() {
- t.Fatalf("LocalAddr returns %q, expected %q", c.LocalAddr().String(),
gaddr.String())
+ la := c.LocalAddr()
+ if la == nil {
+ t.Fatal("LocalAddr failed")
+ }
+ if a, ok := la.(*UDPAddr); !ok || a.Port == 0 {
+ t.Fatal("got %v; expected a proper address with non-zero port number",
la)
}
}

func checkSimpleMulticastListener(t *testing.T, err error, c *UDPConn,
gaddr *UDPAddr) {
- if c.LocalAddr().String() != gaddr.String() {
- t.Fatalf("LocalAddr returns %q, expected %q", c.LocalAddr().String(),
gaddr.String())
+ la := c.LocalAddr()
+ if la == nil {
+ t.Fatal("LocalAddr failed")
+ }
+ if a, ok := la.(*UDPAddr); !ok || a.Port == 0 {
+ t.Fatal("got %v; expected a proper address with non-zero port number",
la)
}
}

Index: src/pkg/net/sock_posix.go
===================================================================
--- a/src/pkg/net/sock_posix.go
+++ b/src/pkg/net/sock_posix.go
@@ -33,13 +33,19 @@
return nil, err
}

- var blsa syscall.Sockaddr
if ulsa != nil {
- if blsa, err = listenerSockaddr(s, f, ulsa, toAddr); err != nil {
+ // We provide a socket that listens to a wildcard
+ // address with reusable UDP port when the given ulsa
+ // is an appropriate UDP multicast address prefix.
+ // This makes it possible for a single UDP listener
+ // to join multiple different group addresses, for
+ // multiple UDP listeners that listen on the same UDP
+ // port to join the same group address.
+ if ulsa, err = listenerSockaddr(s, f, ulsa, toAddr); err != nil {
closesocket(s)
return nil, err
}
- if err = syscall.Bind(s, blsa); err != nil {
+ if err = syscall.Bind(s, ulsa); err != nil {
closesocket(s)
return nil, err
}
@@ -64,12 +70,7 @@
}

lsa, _ := syscall.Getsockname(s)
- var laddr Addr
- if ulsa != nil && blsa != ulsa {
- laddr = toAddr(ulsa)
- } else {
- laddr = toAddr(lsa)
- }
+ laddr := toAddr(lsa)
rsa, _ := syscall.Getpeername(s)
raddr := toAddr(rsa)
fd.setAddr(laddr, raddr)

Search Discussions

  • Rsc at Nov 12, 2012 at 8:53 pm
  • Mikioh Mikioh at Nov 13, 2012 at 3:27 am
    *** Submitted as
    http://code.google.com/p/go/source/detail?r=0b46d6fe2f1c ***

    net: make LocalAddr on multicast UDPConn return a listening address

    The package go.net/ipv4 allows to exist a single UDP listener
    that join multiple different group addresses. That means that
    LocalAddr on multicast UDPConn returns a first joined group
    address is not desirable.

    R=golang-dev, rsc
    CC=golang-dev
    http://codereview.appspot.com/6822108


    http://codereview.appspot.com/6822108/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 12, '12 at 12:47a
activeNov 13, '12 at 3:27a
posts3
users2
websitegolang.org

2 users in discussion

Mikioh Mikioh: 2 posts Rsc: 1 post

People

Translate

site design / logo © 2021 Grokbase