Commit f45339c1 authored by Mikio Hara's avatar Mikio Hara

net: update documentation for TCPConn, TCPListener 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/8147043
parent 32f88f4e
...@@ -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.
// TCP sockets
package net package net
// TCPAddr represents the address of a TCP end point. // TCPAddr represents the address of a TCP end point.
......
...@@ -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.
// TCP sockets for Plan 9
package net package net
import ( import (
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
// +build darwin freebsd linux netbsd openbsd windows // +build darwin freebsd linux netbsd openbsd windows
// TCP sockets
package net package net
import ( import (
...@@ -58,8 +56,8 @@ func (a *TCPAddr) toAddr() sockaddr { ...@@ -58,8 +56,8 @@ func (a *TCPAddr) toAddr() sockaddr {
return a return a
} }
// TCPConn is an implementation of the Conn interface // TCPConn is an implementation of the Conn interface for TCP network
// for TCP network connections. // connections.
type TCPConn struct { type TCPConn struct {
conn conn
} }
...@@ -96,17 +94,17 @@ func (c *TCPConn) CloseWrite() error { ...@@ -96,17 +94,17 @@ func (c *TCPConn) CloseWrite() error {
return c.fd.CloseWrite() return c.fd.CloseWrite()
} }
// SetLinger sets the behavior of Close() on a connection // SetLinger sets the behavior of Close() on a connection which still
// which still has data waiting to be sent or to be acknowledged. // has data waiting to be sent or to be acknowledged.
// //
// If sec < 0 (the default), Close returns immediately and // If sec < 0 (the default), Close returns immediately and the
// the operating system finishes sending the data in the background. // operating system finishes sending the data in the background.
// //
// If sec == 0, Close returns immediately and the operating system // If sec == 0, Close returns immediately and the operating system
// discards any unsent or unacknowledged data. // discards any unsent or unacknowledged data.
// //
// If sec > 0, Close blocks for at most sec seconds waiting for // If sec > 0, Close blocks for at most sec seconds waiting for data
// data to be sent and acknowledged. // to be sent and acknowledged.
func (c *TCPConn) SetLinger(sec int) error { func (c *TCPConn) SetLinger(sec int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
...@@ -124,9 +122,9 @@ func (c *TCPConn) SetKeepAlive(keepalive bool) error { ...@@ -124,9 +122,9 @@ func (c *TCPConn) SetKeepAlive(keepalive bool) error {
} }
// SetNoDelay controls whether the operating system should delay // SetNoDelay controls whether the operating system should delay
// packet transmission in hopes of sending fewer packets // packet transmission in hopes of sending fewer packets (Nagle's
// (Nagle's algorithm). The default is true (no delay), meaning // algorithm). The default is true (no delay), meaning that data is
// that data is sent as soon as possible after a Write. // sent as soon as possible after a Write.
func (c *TCPConn) SetNoDelay(noDelay bool) error { func (c *TCPConn) SetNoDelay(noDelay bool) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
...@@ -135,8 +133,8 @@ func (c *TCPConn) SetNoDelay(noDelay bool) error { ...@@ -135,8 +133,8 @@ func (c *TCPConn) SetNoDelay(noDelay bool) error {
} }
// DialTCP connects to the remote address raddr on the network net, // DialTCP connects to the remote address raddr on the network net,
// which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is used // which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is
// as the local address for the connection. // used as the local address for the connection.
func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) { func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
switch net { switch net {
case "tcp", "tcp4", "tcp6": case "tcp", "tcp4", "tcp6":
...@@ -216,16 +214,15 @@ func spuriousENOTAVAIL(err error) bool { ...@@ -216,16 +214,15 @@ func spuriousENOTAVAIL(err error) bool {
return ok && e.Err == syscall.EADDRNOTAVAIL return ok && e.Err == syscall.EADDRNOTAVAIL
} }
// TCPListener is a TCP network listener. // TCPListener is a TCP network listener. Clients should typically
// Clients should typically use variables of type Listener // use variables of type Listener instead of assuming TCP.
// instead of assuming TCP.
type TCPListener struct { type TCPListener struct {
fd *netFD fd *netFD
} }
// AcceptTCP accepts the next incoming call and returns the new connection // AcceptTCP accepts the next incoming call and returns the new
// and the remote address. // connection and the remote address.
func (l *TCPListener) AcceptTCP() (c *TCPConn, err error) { func (l *TCPListener) AcceptTCP() (*TCPConn, error) {
if l == nil || l.fd == nil { if l == nil || l.fd == nil {
return nil, syscall.EINVAL return nil, syscall.EINVAL
} }
...@@ -236,14 +233,14 @@ func (l *TCPListener) AcceptTCP() (c *TCPConn, err error) { ...@@ -236,14 +233,14 @@ func (l *TCPListener) AcceptTCP() (c *TCPConn, err error) {
return newTCPConn(fd), nil return newTCPConn(fd), nil
} }
// Accept implements the Accept method in the Listener interface; // Accept implements the Accept method in the Listener interface; it
// it waits for the next call and returns a generic Conn. // waits for the next call and returns a generic Conn.
func (l *TCPListener) Accept() (c Conn, err error) { func (l *TCPListener) Accept() (Conn, error) {
c1, err := l.AcceptTCP() c, err := l.AcceptTCP()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return c1, nil return c, nil
} }
// Close stops listening on the TCP address. // Close stops listening on the TCP address.
...@@ -267,8 +264,8 @@ func (l *TCPListener) SetDeadline(t time.Time) error { ...@@ -267,8 +264,8 @@ func (l *TCPListener) SetDeadline(t time.Time) error {
return setDeadline(l.fd, t) return setDeadline(l.fd, t)
} }
// File returns a copy of the underlying os.File, set to blocking mode. // File returns a copy of the underlying os.File, set to blocking
// It is the caller's responsibility to close f when finished. // mode. It is the caller's responsibility to close f when finished.
// Closing l does not affect f, and closing f does not affect l. // Closing l does not affect f, and closing f does not affect l.
func (l *TCPListener) File() (f *os.File, err error) { return l.fd.dup() } func (l *TCPListener) File() (f *os.File, err error) { return l.fd.dup() }
......
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