go.net/ipv4: change I/O method signatures on PacketConn and RawConn

Preserves both Read and Write signatures for the future usage.

R=dave, rsc
CC=golang-dev
https://golang.org/cl/6970048
This commit is contained in:
Mikio Hara
2012-12-21 07:30:42 +09:00
parent cbecf2f725
commit 0e4f6eb3bd
4 changed files with 22 additions and 22 deletions

View File

@@ -69,7 +69,7 @@ func ExampleMulticastUDPListener() {
b := make([]byte, 1500)
for {
n, cm, src, err := p.Read(b)
n, cm, src, err := p.ReadFrom(b)
if err != nil {
log.Fatal(err)
}
@@ -83,7 +83,7 @@ func ExampleMulticastUDPListener() {
}
p.SetTOS(ipv4.DSCP_CS7)
p.SetTTL(16)
_, err = p.Write(b[:n], nil, src)
_, err = p.WriteTo(b[:n], nil, src)
if err != nil {
log.Fatal(err)
}
@@ -94,7 +94,7 @@ func ExampleMulticastUDPListener() {
log.Fatal(err)
}
p.SetMulticastTTL(2)
_, err = p.Write(b[:n], nil, dst)
_, err = p.WriteTo(b[:n], nil, dst)
if err != nil {
log.Fatal(err)
}
@@ -193,7 +193,7 @@ func ExampleIPOSPFListener() {
b := make([]byte, 1500)
for {
iph, p, _, err := r.Read(b)
iph, p, _, err := r.ReadFrom(b)
if err != nil {
log.Fatal(err)
}
@@ -275,7 +275,7 @@ func ExampleWriteIPOSPFHello() {
if err != nil {
return
}
err = r.Write(iph, ospf, nil)
err = r.WriteTo(iph, ospf, nil)
if err != nil {
return
}

View File

@@ -37,10 +37,10 @@ func runPayloadTransponder(t *testing.T, c *ipv4.PacketConn, wb []byte, dst net.
c.SetTTL(i + 1)
}
c.SetDeadline(time.Now().Add(100 * time.Millisecond))
if _, err := c.Write(wb, nil, dst); err != nil {
if _, err := c.WriteTo(wb, nil, dst); err != nil {
t.Fatalf("ipv4.PacketConn.Write failed: %v", err)
}
_, cm, _, err := c.Read(rb)
_, cm, _, err := c.ReadFrom(rb)
if err != nil {
t.Fatalf("ipv4.PacketConn.Read failed: %v", err)
}
@@ -72,10 +72,10 @@ func runDatagramTransponder(t *testing.T, c *ipv4.RawConn, wb []byte, src, dst n
wh.Dst = dst.(*net.IPAddr).IP
}
c.SetDeadline(time.Now().Add(100 * time.Millisecond))
if err := c.Write(wh, wb, nil); err != nil {
if err := c.WriteTo(wh, wb, nil); err != nil {
t.Fatalf("ipv4.RawConn.Write failed: %v", err)
}
rh, _, cm, err := c.Read(rb)
rh, _, cm, err := c.ReadFrom(rb)
if err != nil {
t.Fatalf("ipv4.RawConn.Read failed: %v", err)
}

View File

@@ -17,10 +17,10 @@ type packetHandler struct {
func (c *packetHandler) ok() bool { return c != nil && c.c != nil }
// Read reads an IPv4 datagram from the endpoint c, copying the
// ReadFrom reads an IPv4 datagram from the endpoint c, copying the
// datagram into b. It returns the received datagram as the IPv4
// header h, the payload p and the control message cm.
func (c *packetHandler) Read(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
func (c *packetHandler) ReadFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
if !c.ok() {
return nil, nil, nil, syscall.EINVAL
}
@@ -53,7 +53,7 @@ func slicePacket(b []byte) (h, p []byte, err error) {
return b[:hdrlen], b[hdrlen:], nil
}
// Write writes an IPv4 datagram through the endpoint c, copying the
// WriteTo writes an IPv4 datagram through the endpoint c, copying the
// datagram from the IPv4 header h and the payload p. The control
// message cm allows the datagram path and the outgoing interface to be
// specified. Currently only Linux supports this. The cm may be nil
@@ -73,7 +73,7 @@ func slicePacket(b []byte) (h, p []byte, err error) {
// Src = platform sets an appropriate value if Src is nil
// Dst = <must be specified>
// h.Options = optional
func (c *packetHandler) Write(h *Header, p []byte, cm *ControlMessage) error {
func (c *packetHandler) WriteTo(h *Header, p []byte, cm *ControlMessage) error {
if !c.ok() {
return syscall.EINVAL
}

View File

@@ -17,11 +17,11 @@ type payloadHandler struct {
func (c *payloadHandler) ok() bool { return c != nil && c.c != nil }
// Read reads a payload of the received IPv4 datagram, from the
// ReadFrom reads a payload of the received IPv4 datagram, from the
// endpoint c, copying the payload into b. It returns the number of
// bytes copied into b, the control message cm and the source address
// src of the received datagram.
func (c *payloadHandler) Read(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
if !c.ok() {
return 0, nil, nil, syscall.EINVAL
}
@@ -52,13 +52,13 @@ func (c *payloadHandler) Read(b []byte) (n int, cm *ControlMessage, src net.Addr
return
}
// Write writes a payload of the IPv4 datagram, to the destination
// address dst through the endpoint c, copying the payload from b.
// It returns the number of bytes written. The control message cm
// allows the datagram path and the outgoing interface to be
// specified. Currently only Linux supports this. The cm may be nil
// if control of the outgoing datagram is not required.
func (c *payloadHandler) Write(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
// WriteTo writes a payload of the IPv4 datagram, to the destination
// address dst through the endpoint c, copying the payload from b. It
// returns the number of bytes written. The control message cm allows
// the datagram path and the outgoing interface to be specified.
// Currently only Linux supports this. The cm may be nil if control
// of the outgoing datagram is not required.
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
if !c.ok() {
return 0, syscall.EINVAL
}