From f45339c1f334432e225f611ee37f6e07d382a7d1 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Sun, 31 Mar 2013 16:47:26 +0900 Subject: [PATCH] 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 --- src/pkg/net/tcpsock.go | 2 -- src/pkg/net/tcpsock_plan9.go | 2 -- src/pkg/net/tcpsock_posix.go | 53 +++++++++++++++++------------------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/pkg/net/tcpsock.go b/src/pkg/net/tcpsock.go index 27db115686..4d9ebd214e 100644 --- a/src/pkg/net/tcpsock.go +++ b/src/pkg/net/tcpsock.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// TCP sockets - package net // TCPAddr represents the address of a TCP end point. diff --git a/src/pkg/net/tcpsock_plan9.go b/src/pkg/net/tcpsock_plan9.go index 517e671ac6..96cbcc246b 100644 --- a/src/pkg/net/tcpsock_plan9.go +++ b/src/pkg/net/tcpsock_plan9.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// TCP sockets for Plan 9 - package net import ( diff --git a/src/pkg/net/tcpsock_posix.go b/src/pkg/net/tcpsock_posix.go index 60908c3cd0..8133ca1c11 100644 --- a/src/pkg/net/tcpsock_posix.go +++ b/src/pkg/net/tcpsock_posix.go @@ -4,8 +4,6 @@ // +build darwin freebsd linux netbsd openbsd windows -// TCP sockets - package net import ( @@ -58,8 +56,8 @@ func (a *TCPAddr) toAddr() sockaddr { return a } -// TCPConn is an implementation of the Conn interface -// for TCP network connections. +// TCPConn is an implementation of the Conn interface for TCP network +// connections. type TCPConn struct { conn } @@ -96,17 +94,17 @@ func (c *TCPConn) CloseWrite() error { return c.fd.CloseWrite() } -// SetLinger sets the behavior of Close() on a connection -// which still has data waiting to be sent or to be acknowledged. +// SetLinger sets the behavior of Close() on a connection which still +// has data waiting to be sent or to be acknowledged. // -// If sec < 0 (the default), Close returns immediately and -// the operating system finishes sending the data in the background. +// If sec < 0 (the default), Close returns immediately and the +// operating system finishes sending the data in the background. // // If sec == 0, Close returns immediately and the operating system // discards any unsent or unacknowledged data. // -// If sec > 0, Close blocks for at most sec seconds waiting for -// data to be sent and acknowledged. +// If sec > 0, Close blocks for at most sec seconds waiting for data +// to be sent and acknowledged. func (c *TCPConn) SetLinger(sec int) error { if !c.ok() { return syscall.EINVAL @@ -124,9 +122,9 @@ func (c *TCPConn) SetKeepAlive(keepalive bool) error { } // SetNoDelay controls whether the operating system should delay -// packet transmission in hopes of sending fewer packets -// (Nagle's algorithm). The default is true (no delay), meaning -// that data is sent as soon as possible after a Write. +// packet transmission in hopes of sending fewer packets (Nagle's +// algorithm). The default is true (no delay), meaning that data is +// sent as soon as possible after a Write. func (c *TCPConn) SetNoDelay(noDelay bool) error { if !c.ok() { return syscall.EINVAL @@ -135,8 +133,8 @@ func (c *TCPConn) SetNoDelay(noDelay bool) error { } // 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 -// as the local address for the connection. +// which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is +// used as the local address for the connection. func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) { switch net { case "tcp", "tcp4", "tcp6": @@ -216,16 +214,15 @@ func spuriousENOTAVAIL(err error) bool { return ok && e.Err == syscall.EADDRNOTAVAIL } -// TCPListener is a TCP network listener. -// Clients should typically use variables of type Listener -// instead of assuming TCP. +// TCPListener is a TCP network listener. Clients should typically +// use variables of type Listener instead of assuming TCP. type TCPListener struct { fd *netFD } -// AcceptTCP accepts the next incoming call and returns the new connection -// and the remote address. -func (l *TCPListener) AcceptTCP() (c *TCPConn, err error) { +// AcceptTCP accepts the next incoming call and returns the new +// connection and the remote address. +func (l *TCPListener) AcceptTCP() (*TCPConn, error) { if l == nil || l.fd == nil { return nil, syscall.EINVAL } @@ -236,14 +233,14 @@ func (l *TCPListener) AcceptTCP() (c *TCPConn, err error) { return newTCPConn(fd), nil } -// Accept implements the Accept method in the Listener interface; -// it waits for the next call and returns a generic Conn. -func (l *TCPListener) Accept() (c Conn, err error) { - c1, err := l.AcceptTCP() +// Accept implements the Accept method in the Listener interface; it +// waits for the next call and returns a generic Conn. +func (l *TCPListener) Accept() (Conn, error) { + c, err := l.AcceptTCP() if err != nil { return nil, err } - return c1, nil + return c, nil } // Close stops listening on the TCP address. @@ -267,8 +264,8 @@ func (l *TCPListener) SetDeadline(t time.Time) error { return setDeadline(l.fd, t) } -// File returns a copy of the underlying os.File, set to blocking mode. -// It is the caller's responsibility to close f when finished. +// File returns a copy of the underlying os.File, set to blocking +// 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. func (l *TCPListener) File() (f *os.File, err error) { return l.fd.dup() } -- 2.50.0