diff options
Diffstat (limited to 'src/pkg/net/net.go')
| -rw-r--r-- | src/pkg/net/net.go | 76 |
1 files changed, 64 insertions, 12 deletions
diff --git a/src/pkg/net/net.go b/src/pkg/net/net.go index 609fee242..bf242ff8d 100644 --- a/src/pkg/net/net.go +++ b/src/pkg/net/net.go @@ -2,8 +2,41 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package net provides a portable interface to Unix networks sockets, -// including TCP/IP, UDP, domain name resolution, and Unix domain sockets. +/* +Package net provides a portable interface for network I/O, including +TCP/IP, UDP, domain name resolution, and Unix domain sockets. + +Although the package provides access to low-level networking +primitives, most clients will need only the basic interface provided +by the Dial, Listen, and Accept functions and the associated +Conn and Listener interfaces. The crypto/tls package uses +the same interfaces and similar Dial and Listen functions. + +The Dial function connects to a server: + + conn, err := net.Dial("tcp", "google.com:80") + if err != nil { + // handle error + } + fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") + status, err := bufio.NewReader(conn).ReadString('\n') + // ... + +The Listen function creates servers: + + ln, err := net.Listen("tcp", ":8080") + if err != nil { + // handle error + } + for { + conn, err := ln.Accept() + if err != nil { + // handle error + continue + } + go handleConnection(conn) + } +*/ package net // TODO(rsc): @@ -23,12 +56,12 @@ type Addr interface { // Conn is a generic stream-oriented network connection. type Conn interface { // Read reads data from the connection. - // Read can be made to time out and return a net.Error with Timeout() == true + // Read can be made to time out and return a Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetReadDeadline. Read(b []byte) (n int, err error) // Write writes data to the connection. - // Write can be made to time out and return a net.Error with Timeout() == true + // Write can be made to time out and return a Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetWriteDeadline. Write(b []byte) (n int, err error) @@ -42,21 +75,28 @@ type Conn interface { RemoteAddr() Addr // SetDeadline sets the read and write deadlines associated - // with the connection. + // with the connection. It is equivalent to calling both + // SetReadDeadline and SetWriteDeadline. + // + // A deadline is an absolute time after which I/O operations + // fail with a timeout (see type Error) instead of + // blocking. The deadline applies to all future I/O, not just + // the immediately following call to Read or Write. + // + // An idle timeout can be implemented by repeatedly extending + // the deadline after successful Read or Write calls. + // + // A zero value for t means I/O operations will not time out. SetDeadline(t time.Time) error - // SetReadDeadline sets the deadline for all Read calls to return. - // If the deadline is reached, Read will fail with a timeout - // (see type Error) instead of blocking. + // SetReadDeadline sets the deadline for Read calls. // A zero value for t means Read will not time out. SetReadDeadline(t time.Time) error - // SetWriteDeadline sets the deadline for all Write calls to return. - // If the deadline is reached, Write will fail with a timeout - // (see type Error) instead of blocking. - // A zero value for t means Write will not time out. + // SetWriteDeadline sets the deadline for Write calls. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. + // A zero value for t means Write will not time out. SetWriteDeadline(t time.Time) error } @@ -201,3 +241,15 @@ type UnknownNetworkError string func (e UnknownNetworkError) Error() string { return "unknown network " + string(e) } func (e UnknownNetworkError) Temporary() bool { return false } func (e UnknownNetworkError) Timeout() bool { return false } + +// DNSConfigError represents an error reading the machine's DNS configuration. +type DNSConfigError struct { + Err error +} + +func (e *DNSConfigError) Error() string { + return "error reading DNS config: " + e.Err.Error() +} + +func (e *DNSConfigError) Timeout() bool { return false } +func (e *DNSConfigError) Temporary() bool { return false } |
