Commit e2c453e7 authored by Mikio Hara's avatar Mikio Hara

net: update documentation for UDPConn and related stuff

Closes the API documentation gap between platforms.
Also makes the code textual representation same between platforms.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8148043
parent f45339c1
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// UDP sockets
package net package net
import "errors" import "errors"
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// UDP sockets for Plan 9
package net package net
import ( import (
...@@ -13,15 +11,13 @@ import ( ...@@ -13,15 +11,13 @@ import (
"time" "time"
) )
// UDPConn is the implementation of the Conn and PacketConn // UDPConn is the implementation of the Conn and PacketConn interfaces
// interfaces for UDP network connections. // for UDP network connections.
type UDPConn struct { type UDPConn struct {
conn conn
} }
func newUDPConn(fd *netFD) *UDPConn { func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{conn{fd}} }
return &UDPConn{conn{fd}}
}
// ReadFromUDP reads a UDP packet from c, copying the payload into b. // ReadFromUDP reads a UDP packet from c, copying the payload into b.
// It returns the number of bytes copied into b and the return address // It returns the number of bytes copied into b and the return address
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
// +build darwin freebsd linux netbsd openbsd windows // +build darwin freebsd linux netbsd openbsd windows
// UDP sockets for POSIX
package net package net
import ( import (
...@@ -51,8 +49,8 @@ func (a *UDPAddr) toAddr() sockaddr { ...@@ -51,8 +49,8 @@ func (a *UDPAddr) toAddr() sockaddr {
return a return a
} }
// UDPConn is the implementation of the Conn and PacketConn // UDPConn is the implementation of the Conn and PacketConn interfaces
// interfaces for UDP network connections. // for UDP network connections.
type UDPConn struct { type UDPConn struct {
conn conn
} }
...@@ -63,8 +61,9 @@ func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{conn{fd}} } ...@@ -63,8 +61,9 @@ func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{conn{fd}} }
// It returns the number of bytes copied into b and the return address // It returns the number of bytes copied into b and the return address
// that was on the packet. // that was on the packet.
// //
// ReadFromUDP can be made to time out and return an error with Timeout() == true // ReadFromUDP can be made to time out and return an error with
// after a fixed time limit; see SetDeadline and SetReadDeadline. // Timeout() == true after a fixed time limit; see SetDeadline and
// SetReadDeadline.
func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err error) { func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err error) {
if !c.ok() { if !c.ok() {
return 0, nil, syscall.EINVAL return 0, nil, syscall.EINVAL
...@@ -108,12 +107,13 @@ func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *UDPAddr, ...@@ -108,12 +107,13 @@ func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *UDPAddr,
return return
} }
// WriteToUDP writes a UDP packet to addr via c, copying the payload from b. // WriteToUDP writes a UDP packet to addr via c, copying the payload
// from b.
// //
// WriteToUDP can be made to time out and return // WriteToUDP can be made to time out and return an error with
// an error with Timeout() == true after a fixed time limit; // Timeout() == true after a fixed time limit; see SetDeadline and
// see SetDeadline and SetWriteDeadline. // SetWriteDeadline. On packet-oriented connections, write timeouts
// On packet-oriented connections, write timeouts are rare. // are rare.
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (int, error) { func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
...@@ -158,8 +158,8 @@ func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *UDPAddr) (n, oobn int, err er ...@@ -158,8 +158,8 @@ func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *UDPAddr) (n, oobn int, err er
} }
// DialUDP connects to the remote address raddr on the network net, // DialUDP connects to the remote address raddr on the network net,
// which must be "udp", "udp4", or "udp6". If laddr is not nil, it is used // which must be "udp", "udp4", or "udp6". If laddr is not nil, it is
// as the local address for the connection. // used as the local address for the connection.
func DialUDP(net string, laddr, raddr *UDPAddr) (*UDPConn, error) { func DialUDP(net string, laddr, raddr *UDPAddr) (*UDPConn, error) {
return dialUDP(net, laddr, raddr, noDeadline) return dialUDP(net, laddr, raddr, noDeadline)
} }
...@@ -204,9 +204,9 @@ func ListenUDP(net string, laddr *UDPAddr) (*UDPConn, error) { ...@@ -204,9 +204,9 @@ func ListenUDP(net string, laddr *UDPAddr) (*UDPConn, error) {
} }
// ListenMulticastUDP listens for incoming multicast UDP packets // ListenMulticastUDP listens for incoming multicast UDP packets
// addressed to the group address gaddr on ifi, which specifies // addressed to the group address gaddr on ifi, which specifies the
// the interface to join. ListenMulticastUDP uses default // interface to join. ListenMulticastUDP uses default multicast
// multicast interface if ifi is nil. // interface if ifi is nil.
func ListenMulticastUDP(net string, ifi *Interface, gaddr *UDPAddr) (*UDPConn, error) { func ListenMulticastUDP(net string, ifi *Interface, gaddr *UDPAddr) (*UDPConn, error) {
switch net { switch net {
case "udp", "udp4", "udp6": case "udp", "udp4", "udp6":
......
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