Commit 0d197251 authored by Mikio Hara's avatar Mikio Hara

net: change ListenUnixgram signature to return UnixConn instead of UDPConn

This CL breaks Go 1 API compatibility but it doesn't matter because
previous ListenUnixgram doesn't work in any use cases, oops.

The public API change is:
-pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error)
+pkg net, func ListenUnixgram(string, *UnixAddr) (*UnixConn, error)

Fixes #3875.

R=rsc, golang-dev, dave
CC=golang-dev
https://golang.org/cl/6937059
parent 1947960a
pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error)
pkg text/template/parse, type DotNode bool
pkg text/template/parse, type Node interface { Copy, String, Type }
......@@ -84,6 +84,13 @@ The same is true of the other protocol-specific resolvers <code>ResolveIPAddr</c
<code>ResolveUnixAddr</code>.
</p>
<p>
The previous <code>ListenUnixgram</code> returned <code>UDPConn</code> as
arepresentation of the connection endpoint. The Go 1.1 implementation
returns <code>UnixConn</code> to allow reading and writing
with <code>ReadFrom</code> and <code>WriteTo</code> methods on
the <code>UnixConn</code>.
</p>
<h3 id="time">time</h3>
<p>
......
......@@ -238,7 +238,7 @@ func ListenPacket(net, laddr string) (PacketConn, error) {
if a != nil {
la = a.(*UnixAddr)
}
return DialUnix(net, la, nil)
return ListenUnixgram(net, la)
}
return nil, UnknownNetworkError(net)
}
......@@ -263,9 +263,10 @@ func TestUnixConnSpecificMethods(t *testing.T) {
return
}
p1, p2 := "/tmp/gotest.net1", "/tmp/gotest.net2"
p1, p2, p3 := "/tmp/gotest.net1", "/tmp/gotest.net2", "/tmp/gotest.net3"
os.Remove(p1)
os.Remove(p2)
os.Remove(p3)
a1, err := net.ResolveUnixAddr("unixgram", p1)
if err != nil {
......@@ -305,9 +306,30 @@ func TestUnixConnSpecificMethods(t *testing.T) {
defer c2.Close()
defer os.Remove(p2)
a3, err := net.ResolveUnixAddr("unixgram", p3)
if err != nil {
t.Errorf("net.ResolveUnixAddr failed: %v", err)
return
}
c3, err := net.ListenUnixgram("unixgram", a3)
if err != nil {
t.Errorf("net.ListenUnixgram failed: %v", err)
return
}
c3.LocalAddr()
c3.RemoteAddr()
c3.SetDeadline(time.Now().Add(100 * time.Millisecond))
c3.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
c3.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
c3.SetReadBuffer(2048)
c3.SetWriteBuffer(2048)
defer c3.Close()
defer os.Remove(p3)
wb := []byte("UNIXCONN TEST")
rb1 := make([]byte, 128)
rb2 := make([]byte, 128)
rb3 := make([]byte, 128)
if _, _, err := c1.WriteMsgUnix(wb, nil, a2); err != nil {
t.Errorf("net.UnixConn.WriteMsgUnix failed: %v", err)
return
......@@ -324,9 +346,22 @@ func TestUnixConnSpecificMethods(t *testing.T) {
t.Errorf("net.UnixConn.ReadFromUnix failed: %v", err)
return
}
// TODO: http://golang.org/issue/3875
net.ListenUnixgram("unixgram", nil)
if _, err := c3.WriteToUnix(wb, a1); err != nil {
t.Errorf("net.UnixConn.WriteToUnix failed: %v", err)
return
}
if _, _, err := c1.ReadFromUnix(rb1); err != nil {
t.Errorf("net.UnixConn.ReadFromUnix failed: %v", err)
return
}
if _, err := c2.WriteToUnix(wb, a3); err != nil {
t.Errorf("net.UnixConn.WriteToUnix failed: %v", err)
return
}
if _, _, err := c3.ReadFromUnix(rb3); err != nil {
t.Errorf("net.UnixConn.ReadFromUnix failed: %v", err)
return
}
if f, err := c1.File(); err != nil {
t.Errorf("net.UnixConn.File failed: %v", err)
......
......@@ -64,21 +64,21 @@ func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err
return 0, 0, syscall.EPLAN9
}
// CloseRead shuts down the reading side of the Unix domain
// connection. Most callers should just use Close.
// CloseRead shuts down the reading side of the Unix domain connection.
// Most callers should just use Close.
func (c *UnixConn) CloseRead() error {
return syscall.EPLAN9
}
// CloseWrite shuts down the writing side of the Unix domain
// connection. Most callers should just use Close.
// CloseWrite shuts down the writing side of the Unix domain connection.
// Most callers should just use Close.
func (c *UnixConn) CloseWrite() error {
return syscall.EPLAN9
}
// DialUnix connects to the remote address raddr on the network net,
// which must be "unix" or "unixgram". If laddr is not nil, it is
// used as the local address for the connection.
// which must be "unix", "unixgram" or "unixpacket". If laddr is not
// nil, it is used as the local address for the connection.
func DialUnix(net string, laddr, raddr *UnixAddr) (*UnixConn, error) {
return dialUnix(net, laddr, raddr, noDeadline)
}
......@@ -93,7 +93,8 @@ func dialUnix(net string, laddr, raddr *UnixAddr, deadline time.Time) (*UnixConn
type UnixListener struct{}
// ListenUnix announces on the Unix domain socket laddr and returns a
// Unix listener. Net must be "unix" (stream sockets).
// Unix listener. The network net must be "unix", "unixgram" or
// "unixpacket".
func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error) {
return nil, syscall.EPLAN9
}
......@@ -134,8 +135,8 @@ func (l *UnixListener) File() (*os.File, error) {
// ListenUnixgram listens for incoming Unix datagram packets addressed
// to the local address laddr. The returned connection c's ReadFrom
// and WriteTo methods can be used to receive and send UDP packets
// with per-packet addressing. The network net must be "unixgram".
func ListenUnixgram(net string, laddr *UnixAddr) (*UDPConn, error) {
// and WriteTo methods can be used to receive and send packets with
// per-packet addressing. The network net must be "unixgram".
func ListenUnixgram(net string, laddr *UnixAddr) (*UnixConn, error) {
return nil, syscall.EPLAN9
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment