mirror of
https://github.com/golang/go
synced 2024-10-04 15:09:59 +00:00
src/pkg/[n-z]*: gofix -r error -force=error
R=golang-dev, bsiegert, iant CC=golang-dev https://golang.org/cl/5294074
This commit is contained in:
parent
c2049d2dfe
commit
eb6929299b
|
@ -8,20 +8,18 @@
|
|||
|
||||
package net
|
||||
|
||||
import "os"
|
||||
|
||||
func cgoLookupHost(name string) (addrs []string, err os.Error, completed bool) {
|
||||
func cgoLookupHost(name string) (addrs []string, err error, completed bool) {
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
func cgoLookupPort(network, service string) (port int, err os.Error, completed bool) {
|
||||
func cgoLookupPort(network, service string) (port int, err error, completed bool) {
|
||||
return 0, nil, false
|
||||
}
|
||||
|
||||
func cgoLookupIP(name string) (addrs []IP, err os.Error, completed bool) {
|
||||
func cgoLookupIP(name string) (addrs []IP, err error, completed bool) {
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
func cgoLookupCNAME(name string) (cname string, err os.Error, completed bool) {
|
||||
func cgoLookupCNAME(name string) (cname string, err error, completed bool) {
|
||||
return "", nil, false
|
||||
}
|
||||
|
|
|
@ -18,12 +18,11 @@ package net
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func cgoLookupHost(name string) (addrs []string, err os.Error, completed bool) {
|
||||
func cgoLookupHost(name string) (addrs []string, err error, completed bool) {
|
||||
ip, err, completed := cgoLookupIP(name)
|
||||
for _, p := range ip {
|
||||
addrs = append(addrs, p.String())
|
||||
|
@ -31,7 +30,7 @@ func cgoLookupHost(name string) (addrs []string, err os.Error, completed bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func cgoLookupPort(net, service string) (port int, err os.Error, completed bool) {
|
||||
func cgoLookupPort(net, service string) (port int, err error, completed bool) {
|
||||
var res *C.struct_addrinfo
|
||||
var hints C.struct_addrinfo
|
||||
|
||||
|
@ -78,7 +77,7 @@ func cgoLookupPort(net, service string) (port int, err os.Error, completed bool)
|
|||
return 0, &AddrError{"unknown port", net + "/" + service}, true
|
||||
}
|
||||
|
||||
func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err os.Error, completed bool) {
|
||||
func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, completed bool) {
|
||||
var res *C.struct_addrinfo
|
||||
var hints C.struct_addrinfo
|
||||
|
||||
|
@ -98,11 +97,11 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err os.Error, comp
|
|||
if gerrno == C.EAI_NONAME {
|
||||
str = noSuchHost
|
||||
} else if gerrno == C.EAI_SYSTEM {
|
||||
str = err.String()
|
||||
str = err.Error()
|
||||
} else {
|
||||
str = C.GoString(C.gai_strerror(gerrno))
|
||||
}
|
||||
return nil, "", &DNSError{Error: str, Name: name}, true
|
||||
return nil, "", &DNSError{Err: str, Name: name}, true
|
||||
}
|
||||
defer C.freeaddrinfo(res)
|
||||
if res != nil {
|
||||
|
@ -133,12 +132,12 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err os.Error, comp
|
|||
return addrs, cname, nil, true
|
||||
}
|
||||
|
||||
func cgoLookupIP(name string) (addrs []IP, err os.Error, completed bool) {
|
||||
func cgoLookupIP(name string) (addrs []IP, err error, completed bool) {
|
||||
addrs, _, err, completed = cgoLookupIPCNAME(name)
|
||||
return
|
||||
}
|
||||
|
||||
func cgoLookupCNAME(name string) (cname string, err os.Error, completed bool) {
|
||||
func cgoLookupCNAME(name string) (cname string, err error, completed bool) {
|
||||
_, cname, err, completed = cgoLookupIPCNAME(name)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
package net
|
||||
|
||||
import "os"
|
||||
|
||||
func resolveNetAddr(op, net, addr string) (a Addr, err os.Error) {
|
||||
func resolveNetAddr(op, net, addr string) (a Addr, err error) {
|
||||
if addr == "" {
|
||||
return nil, &OpError{op, net, nil, errMissingAddress}
|
||||
}
|
||||
|
@ -44,7 +42,7 @@ func resolveNetAddr(op, net, addr string) (a Addr, err os.Error) {
|
|||
// Dial("tcp", "google.com:80")
|
||||
// Dial("tcp", "[de:ad:be:ef::ca:fe]:80")
|
||||
//
|
||||
func Dial(net, addr string) (c Conn, err os.Error) {
|
||||
func Dial(net, addr string) (c Conn, err error) {
|
||||
addri, err := resolveNetAddr("dial", net, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -70,7 +68,7 @@ func Dial(net, addr string) (c Conn, err os.Error) {
|
|||
// Listen announces on the local network address laddr.
|
||||
// The network string net must be a stream-oriented
|
||||
// network: "tcp", "tcp4", "tcp6", or "unix", or "unixpacket".
|
||||
func Listen(net, laddr string) (l Listener, err os.Error) {
|
||||
func Listen(net, laddr string) (l Listener, err error) {
|
||||
switch net {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
var la *TCPAddr
|
||||
|
@ -103,7 +101,7 @@ func Listen(net, laddr string) (l Listener, err os.Error) {
|
|||
// ListenPacket announces on the local network address laddr.
|
||||
// The network string net must be a packet-oriented network:
|
||||
// "udp", "udp4", "udp6", or "unixgram".
|
||||
func ListenPacket(net, laddr string) (c PacketConn, err os.Error) {
|
||||
func ListenPacket(net, laddr string) (c PacketConn, err error) {
|
||||
switch net {
|
||||
case "udp", "udp4", "udp6":
|
||||
var la *UDPAddr
|
||||
|
|
|
@ -8,7 +8,6 @@ package dict
|
|||
|
||||
import (
|
||||
"net/textproto"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -20,7 +19,7 @@ type Client struct {
|
|||
|
||||
// Dial returns a new client connected to a dictionary server at
|
||||
// addr on the given network.
|
||||
func Dial(network, addr string) (*Client, os.Error) {
|
||||
func Dial(network, addr string) (*Client, error) {
|
||||
text, err := textproto.Dial(network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -34,7 +33,7 @@ func Dial(network, addr string) (*Client, os.Error) {
|
|||
}
|
||||
|
||||
// Close closes the connection to the dictionary server.
|
||||
func (c *Client) Close() os.Error {
|
||||
func (c *Client) Close() error {
|
||||
return c.text.Close()
|
||||
}
|
||||
|
||||
|
@ -45,7 +44,7 @@ type Dict struct {
|
|||
}
|
||||
|
||||
// Dicts returns a list of the dictionaries available on the server.
|
||||
func (c *Client) Dicts() ([]Dict, os.Error) {
|
||||
func (c *Client) Dicts() ([]Dict, error) {
|
||||
id, err := c.text.Cmd("SHOW DB")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -93,7 +92,7 @@ type Defn struct {
|
|||
// The special dictionary name "!" means to look in all the
|
||||
// server's dictionaries in turn, stopping after finding the word
|
||||
// in one of them.
|
||||
func (c *Client) Define(dict, word string) ([]*Defn, os.Error) {
|
||||
func (c *Client) Define(dict, word string) ([]*Defn, error) {
|
||||
id, err := c.text.Cmd("DEFINE %s %q", dict, word)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -142,7 +141,7 @@ func (c *Client) Define(dict, word string) ([]*Defn, os.Error) {
|
|||
// Fields returns the fields in s.
|
||||
// Fields are space separated unquoted words
|
||||
// or quoted with single or double quote.
|
||||
func fields(s string) ([]string, os.Error) {
|
||||
func fields(s string) ([]string, error) {
|
||||
var v []string
|
||||
i := 0
|
||||
for {
|
||||
|
|
|
@ -7,20 +7,19 @@ package net
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"rand"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// DNSError represents a DNS lookup error.
|
||||
type DNSError struct {
|
||||
Error string // description of the error
|
||||
Err string // description of the error
|
||||
Name string // name looked for
|
||||
Server string // server used
|
||||
IsTimeout bool
|
||||
}
|
||||
|
||||
func (e *DNSError) String() string {
|
||||
func (e *DNSError) Error() string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
|
@ -28,7 +27,7 @@ func (e *DNSError) String() string {
|
|||
if e.Server != "" {
|
||||
s += " on " + e.Server
|
||||
}
|
||||
s += ": " + e.Error
|
||||
s += ": " + e.Err
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -40,10 +39,10 @@ const noSuchHost = "no such host"
|
|||
// reverseaddr returns the in-addr.arpa. or ip6.arpa. hostname of the IP
|
||||
// address addr suitable for rDNS (PTR) record lookup or an error if it fails
|
||||
// to parse the IP address.
|
||||
func reverseaddr(addr string) (arpa string, err os.Error) {
|
||||
func reverseaddr(addr string) (arpa string, err error) {
|
||||
ip := ParseIP(addr)
|
||||
if ip == nil {
|
||||
return "", &DNSError{Error: "unrecognized address", Name: addr}
|
||||
return "", &DNSError{Err: "unrecognized address", Name: addr}
|
||||
}
|
||||
if ip.To4() != nil {
|
||||
return fmt.Sprintf("%d.%d.%d.%d.in-addr.arpa.", ip[15], ip[14], ip[13], ip[12]), nil
|
||||
|
@ -64,18 +63,18 @@ func reverseaddr(addr string) (arpa string, err os.Error) {
|
|||
|
||||
// Find answer for name in dns message.
|
||||
// On return, if err == nil, addrs != nil.
|
||||
func answer(name, server string, dns *dnsMsg, qtype uint16) (cname string, addrs []dnsRR, err os.Error) {
|
||||
func answer(name, server string, dns *dnsMsg, qtype uint16) (cname string, addrs []dnsRR, err error) {
|
||||
addrs = make([]dnsRR, 0, len(dns.answer))
|
||||
|
||||
if dns.rcode == dnsRcodeNameError && dns.recursion_available {
|
||||
return "", nil, &DNSError{Error: noSuchHost, Name: name}
|
||||
return "", nil, &DNSError{Err: noSuchHost, Name: name}
|
||||
}
|
||||
if dns.rcode != dnsRcodeSuccess {
|
||||
// None of the error codes make sense
|
||||
// for the query we sent. If we didn't get
|
||||
// a name error and we didn't get success,
|
||||
// the server is behaving incorrectly.
|
||||
return "", nil, &DNSError{Error: "server misbehaving", Name: name, Server: server}
|
||||
return "", nil, &DNSError{Err: "server misbehaving", Name: name, Server: server}
|
||||
}
|
||||
|
||||
// Look for the name.
|
||||
|
@ -107,12 +106,12 @@ Cname:
|
|||
}
|
||||
}
|
||||
if len(addrs) == 0 {
|
||||
return "", nil, &DNSError{Error: noSuchHost, Name: name, Server: server}
|
||||
return "", nil, &DNSError{Err: noSuchHost, Name: name, Server: server}
|
||||
}
|
||||
return name, addrs, nil
|
||||
}
|
||||
|
||||
return "", nil, &DNSError{Error: "too many redirects", Name: name, Server: server}
|
||||
return "", nil, &DNSError{Err: "too many redirects", Name: name, Server: server}
|
||||
}
|
||||
|
||||
func isDomainName(s string) bool {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
"rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -25,9 +24,9 @@ import (
|
|||
|
||||
// Send a request on the connection and hope for a reply.
|
||||
// Up to cfg.attempts attempts.
|
||||
func exchange(cfg *dnsConfig, c Conn, name string, qtype uint16) (*dnsMsg, os.Error) {
|
||||
func exchange(cfg *dnsConfig, c Conn, name string, qtype uint16) (*dnsMsg, error) {
|
||||
if len(name) >= 256 {
|
||||
return nil, &DNSError{Error: "name too long", Name: name}
|
||||
return nil, &DNSError{Err: "name too long", Name: name}
|
||||
}
|
||||
out := new(dnsMsg)
|
||||
out.id = uint16(rand.Int()) ^ uint16(time.Nanoseconds())
|
||||
|
@ -37,7 +36,7 @@ func exchange(cfg *dnsConfig, c Conn, name string, qtype uint16) (*dnsMsg, os.Er
|
|||
out.recursion_desired = true
|
||||
msg, ok := out.Pack()
|
||||
if !ok {
|
||||
return nil, &DNSError{Error: "internal error - cannot pack message", Name: name}
|
||||
return nil, &DNSError{Err: "internal error - cannot pack message", Name: name}
|
||||
}
|
||||
|
||||
for attempt := 0; attempt < cfg.attempts; attempt++ {
|
||||
|
@ -67,14 +66,14 @@ func exchange(cfg *dnsConfig, c Conn, name string, qtype uint16) (*dnsMsg, os.Er
|
|||
if a := c.RemoteAddr(); a != nil {
|
||||
server = a.String()
|
||||
}
|
||||
return nil, &DNSError{Error: "no answer from server", Name: name, Server: server, IsTimeout: true}
|
||||
return nil, &DNSError{Err: "no answer from server", Name: name, Server: server, IsTimeout: true}
|
||||
}
|
||||
|
||||
// Do a lookup for a single name, which must be rooted
|
||||
// (otherwise answer will not find the answers).
|
||||
func tryOneName(cfg *dnsConfig, name string, qtype uint16) (cname string, addrs []dnsRR, err os.Error) {
|
||||
func tryOneName(cfg *dnsConfig, name string, qtype uint16) (cname string, addrs []dnsRR, err error) {
|
||||
if len(cfg.servers) == 0 {
|
||||
return "", nil, &DNSError{Error: "no DNS servers", Name: name}
|
||||
return "", nil, &DNSError{Err: "no DNS servers", Name: name}
|
||||
}
|
||||
for i := 0; i < len(cfg.servers); i++ {
|
||||
// Calling Dial here is scary -- we have to be sure
|
||||
|
@ -96,7 +95,7 @@ func tryOneName(cfg *dnsConfig, name string, qtype uint16) (cname string, addrs
|
|||
continue
|
||||
}
|
||||
cname, addrs, err = answer(name, server, msg, qtype)
|
||||
if err == nil || err.(*DNSError).Error == noSuchHost {
|
||||
if err == nil || err.(*DNSError).Err == noSuchHost {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -123,15 +122,15 @@ func convertRR_AAAA(records []dnsRR) []IP {
|
|||
}
|
||||
|
||||
var cfg *dnsConfig
|
||||
var dnserr os.Error
|
||||
var dnserr error
|
||||
|
||||
func loadConfig() { cfg, dnserr = dnsReadConfig() }
|
||||
|
||||
var onceLoadConfig sync.Once
|
||||
|
||||
func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err os.Error) {
|
||||
func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err error) {
|
||||
if !isDomainName(name) {
|
||||
return name, nil, &DNSError{Error: "invalid domain name", Name: name}
|
||||
return name, nil, &DNSError{Err: "invalid domain name", Name: name}
|
||||
}
|
||||
onceLoadConfig.Do(loadConfig)
|
||||
if dnserr != nil || cfg == nil {
|
||||
|
@ -186,7 +185,7 @@ func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err os.Erro
|
|||
// Normally we let cgo use the C library resolver instead of
|
||||
// depending on our lookup code, so that Go and C get the same
|
||||
// answers.
|
||||
func goLookupHost(name string) (addrs []string, err os.Error) {
|
||||
func goLookupHost(name string) (addrs []string, err error) {
|
||||
// Use entries from /etc/hosts if they match.
|
||||
addrs = lookupStaticHost(name)
|
||||
if len(addrs) > 0 {
|
||||
|
@ -214,7 +213,7 @@ func goLookupHost(name string) (addrs []string, err os.Error) {
|
|||
// Normally we let cgo use the C library resolver instead of
|
||||
// depending on our lookup code, so that Go and C get the same
|
||||
// answers.
|
||||
func goLookupIP(name string) (addrs []IP, err os.Error) {
|
||||
func goLookupIP(name string) (addrs []IP, err error) {
|
||||
// Use entries from /etc/hosts if possible.
|
||||
haddrs := lookupStaticHost(name)
|
||||
if len(haddrs) > 0 {
|
||||
|
@ -260,7 +259,7 @@ func goLookupIP(name string) (addrs []IP, err os.Error) {
|
|||
// Normally we let cgo use the C library resolver instead of
|
||||
// depending on our lookup code, so that Go and C get the same
|
||||
// answers.
|
||||
func goLookupCNAME(name string) (cname string, err os.Error) {
|
||||
func goLookupCNAME(name string) (cname string, err error) {
|
||||
onceLoadConfig.Do(loadConfig)
|
||||
if dnserr != nil || cfg == nil {
|
||||
err = dnserr
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import "os"
|
||||
|
||||
type dnsConfig struct {
|
||||
servers []string // servers to use
|
||||
search []string // suffixes to append to local name
|
||||
|
@ -19,14 +17,14 @@ type dnsConfig struct {
|
|||
rotate bool // round robin among servers
|
||||
}
|
||||
|
||||
var dnsconfigError os.Error
|
||||
var dnsconfigError error
|
||||
|
||||
type DNSConfigError struct {
|
||||
Error os.Error
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *DNSConfigError) String() string {
|
||||
return "error reading DNS config: " + e.Error.String()
|
||||
func (e *DNSConfigError) Error() string {
|
||||
return "error reading DNS config: " + e.Err.Error()
|
||||
}
|
||||
|
||||
func (e *DNSConfigError) Timeout() bool { return false }
|
||||
|
@ -36,7 +34,7 @@ func (e *DNSConfigError) Temporary() bool { return false }
|
|||
// TODO(rsc): Supposed to call uname() and chop the beginning
|
||||
// of the host name to get the default search domain.
|
||||
// We assume it's in resolv.conf anyway.
|
||||
func dnsReadConfig() (*dnsConfig, os.Error) {
|
||||
func dnsReadConfig() (*dnsConfig, error) {
|
||||
file, err := open("/etc/resolv.conf")
|
||||
if err != nil {
|
||||
return nil, &DNSConfigError{err}
|
||||
|
|
|
@ -46,7 +46,7 @@ type netFD struct {
|
|||
|
||||
type InvalidConnError struct{}
|
||||
|
||||
func (e *InvalidConnError) String() string { return "invalid net.Conn" }
|
||||
func (e *InvalidConnError) Error() string { return "invalid net.Conn" }
|
||||
func (e *InvalidConnError) Temporary() bool { return false }
|
||||
func (e *InvalidConnError) Timeout() bool { return false }
|
||||
|
||||
|
@ -126,7 +126,7 @@ func (s *pollServer) AddFD(fd *netFD, mode int) {
|
|||
|
||||
wake, err := s.poll.AddFD(intfd, mode, false)
|
||||
if err != nil {
|
||||
panic("pollServer AddFD " + err.String())
|
||||
panic("pollServer AddFD " + err.Error())
|
||||
}
|
||||
if wake {
|
||||
doWakeup = true
|
||||
|
@ -227,7 +227,7 @@ func (s *pollServer) Run() {
|
|||
}
|
||||
fd, mode, err := s.poll.WaitFD(s, t)
|
||||
if err != nil {
|
||||
print("pollServer WaitFD: ", err.String(), "\n")
|
||||
print("pollServer WaitFD: ", err.Error(), "\n")
|
||||
return
|
||||
}
|
||||
if fd < 0 {
|
||||
|
@ -271,12 +271,12 @@ var onceStartServer sync.Once
|
|||
func startServer() {
|
||||
p, err := newPollServer()
|
||||
if err != nil {
|
||||
print("Start pollServer: ", err.String(), "\n")
|
||||
print("Start pollServer: ", err.Error(), "\n")
|
||||
}
|
||||
pollserver = p
|
||||
}
|
||||
|
||||
func newFD(fd, family, proto int, net string) (f *netFD, err os.Error) {
|
||||
func newFD(fd, family, proto int, net string) (f *netFD, err error) {
|
||||
onceStartServer.Do(startServer)
|
||||
if e := syscall.SetNonblock(fd, true); e != 0 {
|
||||
return nil, os.Errno(e)
|
||||
|
@ -305,7 +305,7 @@ func (fd *netFD) setAddr(laddr, raddr Addr) {
|
|||
fd.sysfile = os.NewFile(fd.sysfd, fd.net+":"+ls+"->"+rs)
|
||||
}
|
||||
|
||||
func (fd *netFD) connect(ra syscall.Sockaddr) (err os.Error) {
|
||||
func (fd *netFD) connect(ra syscall.Sockaddr) (err error) {
|
||||
e := syscall.Connect(fd.sysfd, ra)
|
||||
if e == syscall.EINPROGRESS {
|
||||
var errno int
|
||||
|
@ -346,7 +346,7 @@ func (fd *netFD) decref() {
|
|||
fd.sysmu.Unlock()
|
||||
}
|
||||
|
||||
func (fd *netFD) Close() os.Error {
|
||||
func (fd *netFD) Close() error {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -358,7 +358,7 @@ func (fd *netFD) Close() os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (fd *netFD) shutdown(how int) os.Error {
|
||||
func (fd *netFD) shutdown(how int) error {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -369,15 +369,15 @@ func (fd *netFD) shutdown(how int) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (fd *netFD) CloseRead() os.Error {
|
||||
func (fd *netFD) CloseRead() error {
|
||||
return fd.shutdown(syscall.SHUT_RD)
|
||||
}
|
||||
|
||||
func (fd *netFD) CloseWrite() os.Error {
|
||||
func (fd *netFD) CloseWrite() error {
|
||||
return fd.shutdown(syscall.SHUT_WR)
|
||||
}
|
||||
|
||||
func (fd *netFD) Read(p []byte) (n int, err os.Error) {
|
||||
func (fd *netFD) Read(p []byte) (n int, err error) {
|
||||
if fd == nil {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ func (fd *netFD) Read(p []byte) (n int, err os.Error) {
|
|||
} else {
|
||||
fd.rdeadline = 0
|
||||
}
|
||||
var oserr os.Error
|
||||
var oserr error
|
||||
for {
|
||||
var errno int
|
||||
n, errno = syscall.Read(fd.sysfile.Fd(), p)
|
||||
|
@ -405,7 +405,7 @@ func (fd *netFD) Read(p []byte) (n int, err os.Error) {
|
|||
n = 0
|
||||
oserr = os.Errno(errno)
|
||||
} else if n == 0 && errno == 0 && fd.proto != syscall.SOCK_DGRAM {
|
||||
err = os.EOF
|
||||
err = io.EOF
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ func (fd *netFD) Read(p []byte) (n int, err os.Error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err os.Error) {
|
||||
func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err error) {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err os.Error) {
|
|||
} else {
|
||||
fd.rdeadline = 0
|
||||
}
|
||||
var oserr os.Error
|
||||
var oserr error
|
||||
for {
|
||||
var errno int
|
||||
n, sa, errno = syscall.Recvfrom(fd.sysfd, p, 0)
|
||||
|
@ -448,7 +448,7 @@ func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err os.Error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.Sockaddr, err os.Error) {
|
||||
func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.Sockaddr, err error) {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return 0, 0, 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
|
|||
} else {
|
||||
fd.rdeadline = 0
|
||||
}
|
||||
var oserr os.Error
|
||||
var oserr error
|
||||
for {
|
||||
var errno int
|
||||
n, oobn, flags, sa, errno = syscall.Recvmsg(fd.sysfd, p, oob, 0)
|
||||
|
@ -473,7 +473,7 @@ func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
|
|||
oserr = os.Errno(errno)
|
||||
}
|
||||
if n == 0 {
|
||||
oserr = os.EOF
|
||||
oserr = io.EOF
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
|
|||
return
|
||||
}
|
||||
|
||||
func (fd *netFD) Write(p []byte) (n int, err os.Error) {
|
||||
func (fd *netFD) Write(p []byte) (n int, err error) {
|
||||
if fd == nil {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ func (fd *netFD) Write(p []byte) (n int, err os.Error) {
|
|||
fd.wdeadline = 0
|
||||
}
|
||||
nn := 0
|
||||
var oserr os.Error
|
||||
var oserr error
|
||||
|
||||
for {
|
||||
n, errno := syscall.Write(fd.sysfile.Fd(), p[nn:])
|
||||
|
@ -531,7 +531,7 @@ func (fd *netFD) Write(p []byte) (n int, err os.Error) {
|
|||
return nn, err
|
||||
}
|
||||
|
||||
func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err os.Error) {
|
||||
func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err error) {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -544,7 +544,7 @@ func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err os.Error) {
|
|||
} else {
|
||||
fd.wdeadline = 0
|
||||
}
|
||||
var oserr os.Error
|
||||
var oserr error
|
||||
for {
|
||||
errno := syscall.Sendto(fd.sysfd, p, 0, sa)
|
||||
if errno == syscall.EAGAIN && fd.wdeadline >= 0 {
|
||||
|
@ -564,7 +564,7 @@ func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err os.Error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oobn int, err os.Error) {
|
||||
func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oobn int, err error) {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return 0, 0, os.EINVAL
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob
|
|||
} else {
|
||||
fd.wdeadline = 0
|
||||
}
|
||||
var oserr os.Error
|
||||
var oserr error
|
||||
for {
|
||||
var errno int
|
||||
errno = syscall.Sendmsg(fd.sysfd, p, oob, sa, 0)
|
||||
|
@ -599,7 +599,7 @@ func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob
|
|||
return
|
||||
}
|
||||
|
||||
func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.Error) {
|
||||
func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err error) {
|
||||
if fd == nil || fd.sysfile == nil {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
|
@ -647,7 +647,7 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
|
|||
return nfd, nil
|
||||
}
|
||||
|
||||
func (fd *netFD) dup() (f *os.File, err os.Error) {
|
||||
func (fd *netFD) dup() (f *os.File, err error) {
|
||||
ns, e := syscall.Dup(fd.sysfd)
|
||||
if e != 0 {
|
||||
return nil, &OpError{"dup", fd.net, fd.laddr, os.Errno(e)}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
@ -21,7 +22,7 @@ type pollster struct {
|
|||
kbuf [1]syscall.Kevent_t
|
||||
}
|
||||
|
||||
func newpollster() (p *pollster, err os.Error) {
|
||||
func newpollster() (p *pollster, err error) {
|
||||
p = new(pollster)
|
||||
var e int
|
||||
if p.kq, e = syscall.Kqueue(); e != 0 {
|
||||
|
@ -31,7 +32,7 @@ func newpollster() (p *pollster, err os.Error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
|
||||
// pollServer is locked.
|
||||
|
||||
var kmode int
|
||||
|
@ -56,7 +57,7 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
|
|||
return false, os.NewSyscallError("kevent", e)
|
||||
}
|
||||
if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
|
||||
return false, os.NewError("kqueue phase error")
|
||||
return false, errors.New("kqueue phase error")
|
||||
}
|
||||
if ev.Data != 0 {
|
||||
return false, os.Errno(int(ev.Data))
|
||||
|
@ -81,7 +82,7 @@ func (p *pollster) DelFD(fd int, mode int) {
|
|||
syscall.Kevent(p.kq, p.kbuf[0:], p.kbuf[0:], nil)
|
||||
}
|
||||
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.Error) {
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err error) {
|
||||
var t *syscall.Timespec
|
||||
for len(p.events) == 0 {
|
||||
if nsec > 0 {
|
||||
|
@ -117,4 +118,4 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.E
|
|||
return fd, mode, nil
|
||||
}
|
||||
|
||||
func (p *pollster) Close() os.Error { return os.NewSyscallError("close", syscall.Close(p.kq)) }
|
||||
func (p *pollster) Close() error { return os.NewSyscallError("close", syscall.Close(p.kq)) }
|
||||
|
|
|
@ -21,7 +21,7 @@ type pollster struct {
|
|||
kbuf [1]syscall.Kevent_t
|
||||
}
|
||||
|
||||
func newpollster() (p *pollster, err os.Error) {
|
||||
func newpollster() (p *pollster, err error) {
|
||||
p = new(pollster)
|
||||
var e int
|
||||
if p.kq, e = syscall.Kqueue(); e != 0 {
|
||||
|
@ -31,7 +31,7 @@ func newpollster() (p *pollster, err os.Error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
|
||||
// pollServer is locked.
|
||||
|
||||
var kmode int
|
||||
|
@ -77,7 +77,7 @@ func (p *pollster) DelFD(fd int, mode int) {
|
|||
syscall.Kevent(p.kq, p.kbuf[:], nil, nil)
|
||||
}
|
||||
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.Error) {
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err error) {
|
||||
var t *syscall.Timespec
|
||||
for len(p.events) == 0 {
|
||||
if nsec > 0 {
|
||||
|
@ -113,4 +113,4 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.E
|
|||
return fd, mode, nil
|
||||
}
|
||||
|
||||
func (p *pollster) Close() os.Error { return os.NewSyscallError("close", syscall.Close(p.kq)) }
|
||||
func (p *pollster) Close() error { return os.NewSyscallError("close", syscall.Close(p.kq)) }
|
||||
|
|
|
@ -33,7 +33,7 @@ type pollster struct {
|
|||
ctlEvent syscall.EpollEvent
|
||||
}
|
||||
|
||||
func newpollster() (p *pollster, err os.Error) {
|
||||
func newpollster() (p *pollster, err error) {
|
||||
p = new(pollster)
|
||||
var e int
|
||||
|
||||
|
@ -47,7 +47,7 @@ func newpollster() (p *pollster, err os.Error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
|
||||
// pollServer is locked.
|
||||
|
||||
var already bool
|
||||
|
@ -130,7 +130,7 @@ func (p *pollster) DelFD(fd int, mode int) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.Error) {
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err error) {
|
||||
for len(p.waitEvents) == 0 {
|
||||
var msec int = -1
|
||||
if nsec > 0 {
|
||||
|
@ -177,6 +177,6 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.E
|
|||
return fd, 'r', nil
|
||||
}
|
||||
|
||||
func (p *pollster) Close() os.Error {
|
||||
func (p *pollster) Close() error {
|
||||
return os.NewSyscallError("close", syscall.Close(p.epfd))
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ type pollster struct {
|
|||
kbuf [1]syscall.Kevent_t
|
||||
}
|
||||
|
||||
func newpollster() (p *pollster, err os.Error) {
|
||||
func newpollster() (p *pollster, err error) {
|
||||
p = new(pollster)
|
||||
var e int
|
||||
if p.kq, e = syscall.Kqueue(); e != 0 {
|
||||
|
@ -31,7 +31,7 @@ func newpollster() (p *pollster, err os.Error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
|
||||
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
|
||||
// pollServer is locked.
|
||||
|
||||
var kmode int
|
||||
|
@ -77,7 +77,7 @@ func (p *pollster) DelFD(fd int, mode int) {
|
|||
syscall.Kevent(p.kq, p.kbuf[:], nil, nil)
|
||||
}
|
||||
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.Error) {
|
||||
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err error) {
|
||||
var t *syscall.Timespec
|
||||
for len(p.events) == 0 {
|
||||
if nsec > 0 {
|
||||
|
@ -113,4 +113,4 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.E
|
|||
return fd, mode, nil
|
||||
}
|
||||
|
||||
func (p *pollster) Close() os.Error { return os.NewSyscallError("close", syscall.Close(p.kq)) }
|
||||
func (p *pollster) Close() error { return os.NewSyscallError("close", syscall.Close(p.kq)) }
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
@ -15,11 +16,11 @@ import (
|
|||
|
||||
type InvalidConnError struct{}
|
||||
|
||||
func (e *InvalidConnError) String() string { return "invalid net.Conn" }
|
||||
func (e *InvalidConnError) Error() string { return "invalid net.Conn" }
|
||||
func (e *InvalidConnError) Temporary() bool { return false }
|
||||
func (e *InvalidConnError) Timeout() bool { return false }
|
||||
|
||||
var initErr os.Error
|
||||
var initErr error
|
||||
|
||||
func init() {
|
||||
var d syscall.WSAData
|
||||
|
@ -151,7 +152,7 @@ func (s *ioSrv) ProcessRemoteIO() {
|
|||
// ExecIO executes a single io operation. It either executes it
|
||||
// inline, or, if timeouts are employed, passes the request onto
|
||||
// a special goroutine and waits for completion or cancels request.
|
||||
func (s *ioSrv) ExecIO(oi anOpIface, deadline_delta int64) (n int, err os.Error) {
|
||||
func (s *ioSrv) ExecIO(oi anOpIface, deadline_delta int64) (n int, err error) {
|
||||
var e int
|
||||
o := oi.Op()
|
||||
if deadline_delta > 0 {
|
||||
|
@ -249,7 +250,7 @@ func allocFD(fd syscall.Handle, family, proto int, net string) (f *netFD) {
|
|||
return f
|
||||
}
|
||||
|
||||
func newFD(fd syscall.Handle, family, proto int, net string) (f *netFD, err os.Error) {
|
||||
func newFD(fd syscall.Handle, family, proto int, net string) (f *netFD, err error) {
|
||||
if initErr != nil {
|
||||
return nil, initErr
|
||||
}
|
||||
|
@ -266,7 +267,7 @@ func (fd *netFD) setAddr(laddr, raddr Addr) {
|
|||
fd.raddr = raddr
|
||||
}
|
||||
|
||||
func (fd *netFD) connect(ra syscall.Sockaddr) (err os.Error) {
|
||||
func (fd *netFD) connect(ra syscall.Sockaddr) (err error) {
|
||||
e := syscall.Connect(fd.sysfd, ra)
|
||||
if e != 0 {
|
||||
return os.Errno(e)
|
||||
|
@ -300,7 +301,7 @@ func (fd *netFD) decref() {
|
|||
fd.sysmu.Unlock()
|
||||
}
|
||||
|
||||
func (fd *netFD) Close() os.Error {
|
||||
func (fd *netFD) Close() error {
|
||||
if fd == nil || fd.sysfd == syscall.InvalidHandle {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -312,7 +313,7 @@ func (fd *netFD) Close() os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (fd *netFD) shutdown(how int) os.Error {
|
||||
func (fd *netFD) shutdown(how int) error {
|
||||
if fd == nil || fd.sysfd == syscall.InvalidHandle {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -323,11 +324,11 @@ func (fd *netFD) shutdown(how int) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (fd *netFD) CloseRead() os.Error {
|
||||
func (fd *netFD) CloseRead() error {
|
||||
return fd.shutdown(syscall.SHUT_RD)
|
||||
}
|
||||
|
||||
func (fd *netFD) CloseWrite() os.Error {
|
||||
func (fd *netFD) CloseWrite() error {
|
||||
return fd.shutdown(syscall.SHUT_WR)
|
||||
}
|
||||
|
||||
|
@ -346,7 +347,7 @@ func (o *readOp) Name() string {
|
|||
return "WSARecv"
|
||||
}
|
||||
|
||||
func (fd *netFD) Read(buf []byte) (n int, err os.Error) {
|
||||
func (fd *netFD) Read(buf []byte) (n int, err error) {
|
||||
if fd == nil {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -361,7 +362,7 @@ func (fd *netFD) Read(buf []byte) (n int, err os.Error) {
|
|||
o.Init(fd, buf, 'r')
|
||||
n, err = iosrv.ExecIO(&o, fd.rdeadline_delta)
|
||||
if err == nil && n == 0 {
|
||||
err = os.EOF
|
||||
err = io.EOF
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -383,7 +384,7 @@ func (o *readFromOp) Name() string {
|
|||
return "WSARecvFrom"
|
||||
}
|
||||
|
||||
func (fd *netFD) ReadFrom(buf []byte) (n int, sa syscall.Sockaddr, err os.Error) {
|
||||
func (fd *netFD) ReadFrom(buf []byte) (n int, sa syscall.Sockaddr, err error) {
|
||||
if fd == nil {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -423,7 +424,7 @@ func (o *writeOp) Name() string {
|
|||
return "WSASend"
|
||||
}
|
||||
|
||||
func (fd *netFD) Write(buf []byte) (n int, err os.Error) {
|
||||
func (fd *netFD) Write(buf []byte) (n int, err error) {
|
||||
if fd == nil {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -455,7 +456,7 @@ func (o *writeToOp) Name() string {
|
|||
return "WSASendto"
|
||||
}
|
||||
|
||||
func (fd *netFD) WriteTo(buf []byte, sa syscall.Sockaddr) (n int, err os.Error) {
|
||||
func (fd *netFD) WriteTo(buf []byte, sa syscall.Sockaddr) (n int, err error) {
|
||||
if fd == nil {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -494,7 +495,7 @@ func (o *acceptOp) Name() string {
|
|||
return "AcceptEx"
|
||||
}
|
||||
|
||||
func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.Error) {
|
||||
func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err error) {
|
||||
if fd == nil || fd.sysfd == syscall.InvalidHandle {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
|
@ -551,15 +552,15 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
|
|||
|
||||
// Unimplemented functions.
|
||||
|
||||
func (fd *netFD) dup() (f *os.File, err os.Error) {
|
||||
func (fd *netFD) dup() (f *os.File, err error) {
|
||||
// TODO: Implement this
|
||||
return nil, os.NewSyscallError("dup", syscall.EWINDOWS)
|
||||
}
|
||||
|
||||
func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.Sockaddr, err os.Error) {
|
||||
func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.Sockaddr, err error) {
|
||||
return 0, 0, 0, nil, os.EAFNOSUPPORT
|
||||
}
|
||||
|
||||
func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oobn int, err os.Error) {
|
||||
func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oobn int, err error) {
|
||||
return 0, 0, os.EAFNOSUPPORT
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func newFileFD(f *os.File) (nfd *netFD, err os.Error) {
|
||||
func newFileFD(f *os.File) (nfd *netFD, err error) {
|
||||
fd, errno := syscall.Dup(f.Fd())
|
||||
if errno != 0 {
|
||||
return nil, os.NewSyscallError("dup", errno)
|
||||
|
@ -67,7 +67,7 @@ func newFileFD(f *os.File) (nfd *netFD, err os.Error) {
|
|||
// the open file f. It is the caller's responsibility to close f when
|
||||
// finished. Closing c does not affect f, and closing f does not
|
||||
// affect c.
|
||||
func FileConn(f *os.File) (c Conn, err os.Error) {
|
||||
func FileConn(f *os.File) (c Conn, err error) {
|
||||
fd, err := newFileFD(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -90,7 +90,7 @@ func FileConn(f *os.File) (c Conn, err os.Error) {
|
|||
// to the open file f. It is the caller's responsibility to close l
|
||||
// when finished. Closing c does not affect l, and closing l does not
|
||||
// affect c.
|
||||
func FileListener(f *os.File) (l Listener, err os.Error) {
|
||||
func FileListener(f *os.File) (l Listener, err error) {
|
||||
fd, err := newFileFD(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -109,7 +109,7 @@ func FileListener(f *os.File) (l Listener, err os.Error) {
|
|||
// corresponding to the open file f. It is the caller's
|
||||
// responsibility to close f when finished. Closing c does not affect
|
||||
// f, and closing f does not affect c.
|
||||
func FilePacketConn(f *os.File) (c PacketConn, err os.Error) {
|
||||
func FilePacketConn(f *os.File) (c PacketConn, err error) {
|
||||
fd, err := newFileFD(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// the open file f. It is the caller's responsibility to close f when
|
||||
// finished. Closing c does not affect f, and closing f does not
|
||||
// affect c.
|
||||
func FileConn(f *os.File) (c Conn, err os.Error) {
|
||||
func FileConn(f *os.File) (c Conn, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ func FileConn(f *os.File) (c Conn, err os.Error) {
|
|||
// to the open file f. It is the caller's responsibility to close l
|
||||
// when finished. Closing c does not affect l, and closing l does not
|
||||
// affect c.
|
||||
func FileListener(f *os.File) (l Listener, err os.Error) {
|
||||
func FileListener(f *os.File) (l Listener, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,6 @@ func FileListener(f *os.File) (l Listener, err os.Error) {
|
|||
// corresponding to the open file f. It is the caller's
|
||||
// responsibility to close f when finished. Closing c does not affect
|
||||
// f, and closing f does not affect c.
|
||||
func FilePacketConn(f *os.File) (c PacketConn, err os.Error) {
|
||||
func FilePacketConn(f *os.File) (c PacketConn, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
|
|
@ -14,17 +14,17 @@ import (
|
|||
|
||||
type listenerFile interface {
|
||||
Listener
|
||||
File() (f *os.File, err os.Error)
|
||||
File() (f *os.File, err error)
|
||||
}
|
||||
|
||||
type packetConnFile interface {
|
||||
PacketConn
|
||||
File() (f *os.File, err os.Error)
|
||||
File() (f *os.File, err error)
|
||||
}
|
||||
|
||||
type connFile interface {
|
||||
Conn
|
||||
File() (f *os.File, err os.Error)
|
||||
File() (f *os.File, err error)
|
||||
}
|
||||
|
||||
func testFileListener(t *testing.T, net, laddr string) {
|
||||
|
|
|
@ -9,17 +9,17 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func FileConn(f *os.File) (c Conn, err os.Error) {
|
||||
func FileConn(f *os.File) (c Conn, err error) {
|
||||
// TODO: Implement this
|
||||
return nil, os.NewSyscallError("FileConn", syscall.EWINDOWS)
|
||||
}
|
||||
|
||||
func FileListener(f *os.File) (l Listener, err os.Error) {
|
||||
func FileListener(f *os.File) (l Listener, err error) {
|
||||
// TODO: Implement this
|
||||
return nil, os.NewSyscallError("FileListener", syscall.EWINDOWS)
|
||||
}
|
||||
|
||||
func FilePacketConn(f *os.File) (c PacketConn, err os.Error) {
|
||||
func FilePacketConn(f *os.File) (c PacketConn, err error) {
|
||||
// TODO: Implement this
|
||||
return nil, os.NewSyscallError("FilePacketConn", syscall.EWINDOWS)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ package net
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// A HardwareAddr represents a physical hardware address.
|
||||
|
@ -34,7 +34,7 @@ func (a HardwareAddr) String() string {
|
|||
// 01-23-45-67-89-ab-cd-ef
|
||||
// 0123.4567.89ab
|
||||
// 0123.4567.89ab.cdef
|
||||
func ParseMAC(s string) (hw HardwareAddr, err os.Error) {
|
||||
func ParseMAC(s string) (hw HardwareAddr, err error) {
|
||||
if len(s) < 14 {
|
||||
goto error
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func ParseMAC(s string) (hw HardwareAddr, err os.Error) {
|
|||
return hw, nil
|
||||
|
||||
error:
|
||||
return nil, os.NewError("invalid MAC address: " + s)
|
||||
return nil, errors.New("invalid MAC address: " + s)
|
||||
}
|
||||
|
||||
// Interface represents a mapping between network interface name
|
||||
|
@ -129,37 +129,37 @@ func (f Flags) String() string {
|
|||
}
|
||||
|
||||
// Addrs returns interface addresses for a specific interface.
|
||||
func (ifi *Interface) Addrs() ([]Addr, os.Error) {
|
||||
func (ifi *Interface) Addrs() ([]Addr, error) {
|
||||
if ifi == nil {
|
||||
return nil, os.NewError("net: invalid interface")
|
||||
return nil, errors.New("net: invalid interface")
|
||||
}
|
||||
return interfaceAddrTable(ifi.Index)
|
||||
}
|
||||
|
||||
// MulticastAddrs returns multicast, joined group addresses for
|
||||
// a specific interface.
|
||||
func (ifi *Interface) MulticastAddrs() ([]Addr, os.Error) {
|
||||
func (ifi *Interface) MulticastAddrs() ([]Addr, error) {
|
||||
if ifi == nil {
|
||||
return nil, os.NewError("net: invalid interface")
|
||||
return nil, errors.New("net: invalid interface")
|
||||
}
|
||||
return interfaceMulticastAddrTable(ifi.Index)
|
||||
}
|
||||
|
||||
// Interfaces returns a list of the systems's network interfaces.
|
||||
func Interfaces() ([]Interface, os.Error) {
|
||||
func Interfaces() ([]Interface, error) {
|
||||
return interfaceTable(0)
|
||||
}
|
||||
|
||||
// InterfaceAddrs returns a list of the system's network interface
|
||||
// addresses.
|
||||
func InterfaceAddrs() ([]Addr, os.Error) {
|
||||
func InterfaceAddrs() ([]Addr, error) {
|
||||
return interfaceAddrTable(0)
|
||||
}
|
||||
|
||||
// InterfaceByIndex returns the interface specified by index.
|
||||
func InterfaceByIndex(index int) (*Interface, os.Error) {
|
||||
func InterfaceByIndex(index int) (*Interface, error) {
|
||||
if index <= 0 {
|
||||
return nil, os.NewError("net: invalid interface index")
|
||||
return nil, errors.New("net: invalid interface index")
|
||||
}
|
||||
ift, err := interfaceTable(index)
|
||||
if err != nil {
|
||||
|
@ -168,13 +168,13 @@ func InterfaceByIndex(index int) (*Interface, os.Error) {
|
|||
for _, ifi := range ift {
|
||||
return &ifi, nil
|
||||
}
|
||||
return nil, os.NewError("net: no such interface")
|
||||
return nil, errors.New("net: no such interface")
|
||||
}
|
||||
|
||||
// InterfaceByName returns the interface specified by name.
|
||||
func InterfaceByName(name string) (*Interface, os.Error) {
|
||||
func InterfaceByName(name string) (*Interface, error) {
|
||||
if name == "" {
|
||||
return nil, os.NewError("net: invalid interface name")
|
||||
return nil, errors.New("net: invalid interface name")
|
||||
}
|
||||
ift, err := interfaceTable(0)
|
||||
if err != nil {
|
||||
|
@ -185,5 +185,5 @@ func InterfaceByName(name string) (*Interface, os.Error) {
|
|||
return &ifi, nil
|
||||
}
|
||||
}
|
||||
return nil, os.NewError("net: no such interface")
|
||||
return nil, errors.New("net: no such interface")
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
// If the ifindex is zero, interfaceTable returns mappings of all
|
||||
// network interfaces. Otheriwse it returns a mapping of a specific
|
||||
// interface.
|
||||
func interfaceTable(ifindex int) ([]Interface, os.Error) {
|
||||
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||
var (
|
||||
tab []byte
|
||||
e int
|
||||
|
@ -51,7 +51,7 @@ func interfaceTable(ifindex int) ([]Interface, os.Error) {
|
|||
return ift, nil
|
||||
}
|
||||
|
||||
func newLink(m *syscall.InterfaceMessage) ([]Interface, os.Error) {
|
||||
func newLink(m *syscall.InterfaceMessage) ([]Interface, error) {
|
||||
var ift []Interface
|
||||
|
||||
sas, e := syscall.ParseRoutingSockaddr(m)
|
||||
|
@ -107,7 +107,7 @@ func linkFlags(rawFlags int32) Flags {
|
|||
// If the ifindex is zero, interfaceAddrTable returns addresses
|
||||
// for all network interfaces. Otherwise it returns addresses
|
||||
// for a specific interface.
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
||||
var (
|
||||
tab []byte
|
||||
e int
|
||||
|
@ -141,7 +141,7 @@ func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
|||
return ifat, nil
|
||||
}
|
||||
|
||||
func newAddr(m *syscall.InterfaceAddrMessage) ([]Addr, os.Error) {
|
||||
func newAddr(m *syscall.InterfaceAddrMessage) ([]Addr, error) {
|
||||
var ifat []Addr
|
||||
|
||||
sas, e := syscall.ParseRoutingSockaddr(m)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// If the ifindex is zero, interfaceMulticastAddrTable returns
|
||||
// addresses for all network interfaces. Otherwise it returns
|
||||
// addresses for a specific interface.
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
|
||||
var (
|
||||
tab []byte
|
||||
e int
|
||||
|
@ -48,7 +48,7 @@ func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
|||
return ifmat, nil
|
||||
}
|
||||
|
||||
func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, os.Error) {
|
||||
func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, error) {
|
||||
var ifmat []Addr
|
||||
|
||||
sas, e := syscall.ParseRoutingSockaddr(m)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// If the ifindex is zero, interfaceMulticastAddrTable returns
|
||||
// addresses for all network interfaces. Otherwise it returns
|
||||
// addresses for a specific interface.
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
|
||||
var (
|
||||
tab []byte
|
||||
e int
|
||||
|
@ -48,7 +48,7 @@ func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
|||
return ifmat, nil
|
||||
}
|
||||
|
||||
func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, os.Error) {
|
||||
func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, error) {
|
||||
var ifmat []Addr
|
||||
|
||||
sas, e := syscall.ParseRoutingSockaddr(m)
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
// If the ifindex is zero, interfaceTable returns mappings of all
|
||||
// network interfaces. Otheriwse it returns a mapping of a specific
|
||||
// interface.
|
||||
func interfaceTable(ifindex int) ([]Interface, os.Error) {
|
||||
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||
var (
|
||||
ift []Interface
|
||||
tab []byte
|
||||
|
@ -101,11 +101,11 @@ func linkFlags(rawFlags uint32) Flags {
|
|||
// If the ifindex is zero, interfaceAddrTable returns addresses
|
||||
// for all network interfaces. Otherwise it returns addresses
|
||||
// for a specific interface.
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
||||
var (
|
||||
tab []byte
|
||||
e int
|
||||
err os.Error
|
||||
err error
|
||||
ifat []Addr
|
||||
msgs []syscall.NetlinkMessage
|
||||
)
|
||||
|
@ -128,7 +128,7 @@ func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
|||
return ifat, nil
|
||||
}
|
||||
|
||||
func addrTable(msgs []syscall.NetlinkMessage, ifindex int) ([]Addr, os.Error) {
|
||||
func addrTable(msgs []syscall.NetlinkMessage, ifindex int) ([]Addr, error) {
|
||||
var ifat []Addr
|
||||
|
||||
for _, m := range msgs {
|
||||
|
@ -175,10 +175,10 @@ func newAddr(attrs []syscall.NetlinkRouteAttr, family int) []Addr {
|
|||
// If the ifindex is zero, interfaceMulticastAddrTable returns
|
||||
// addresses for all network interfaces. Otherwise it returns
|
||||
// addresses for a specific interface.
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
|
||||
var (
|
||||
ifi *Interface
|
||||
err os.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if ifindex > 0 {
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
|
||||
package net
|
||||
|
||||
import "os"
|
||||
|
||||
// If the ifindex is zero, interfaceMulticastAddrTable returns
|
||||
// addresses for all network interfaces. Otherwise it returns
|
||||
// addresses for a specific interface.
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -8,25 +8,23 @@
|
|||
|
||||
package net
|
||||
|
||||
import "os"
|
||||
|
||||
// If the ifindex is zero, interfaceTable returns mappings of all
|
||||
// network interfaces. Otheriwse it returns a mapping of a specific
|
||||
// interface.
|
||||
func interfaceTable(ifindex int) ([]Interface, os.Error) {
|
||||
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// If the ifindex is zero, interfaceAddrTable returns addresses
|
||||
// for all network interfaces. Otherwise it returns addresses
|
||||
// for a specific interface.
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// If the ifindex is zero, interfaceMulticastAddrTable returns
|
||||
// addresses for all network interfaces. Otherwise it returns
|
||||
// addresses for a specific interface.
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ package net
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -101,11 +100,11 @@ var mactests = []struct {
|
|||
{"0123.4567.89AB.CDEF", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, ""},
|
||||
}
|
||||
|
||||
func match(err os.Error, s string) bool {
|
||||
func match(err error, s string) bool {
|
||||
if s == "" {
|
||||
return err == nil
|
||||
}
|
||||
return err != nil && strings.Contains(err.String(), s)
|
||||
return err != nil && strings.Contains(err.Error(), s)
|
||||
}
|
||||
|
||||
func TestParseMAC(t *testing.T) {
|
||||
|
|
|
@ -21,7 +21,7 @@ func bytePtrToString(p *uint8) string {
|
|||
return string(a[:i])
|
||||
}
|
||||
|
||||
func getAdapterList() (*syscall.IpAdapterInfo, os.Error) {
|
||||
func getAdapterList() (*syscall.IpAdapterInfo, error) {
|
||||
b := make([]byte, 1000)
|
||||
l := uint32(len(b))
|
||||
a := (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
|
||||
|
@ -37,7 +37,7 @@ func getAdapterList() (*syscall.IpAdapterInfo, os.Error) {
|
|||
return a, nil
|
||||
}
|
||||
|
||||
func getInterfaceList() ([]syscall.InterfaceInfo, os.Error) {
|
||||
func getInterfaceList() ([]syscall.InterfaceInfo, error) {
|
||||
s, e := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
|
||||
if e != 0 {
|
||||
return nil, os.NewSyscallError("Socket", e)
|
||||
|
@ -58,7 +58,7 @@ func getInterfaceList() ([]syscall.InterfaceInfo, os.Error) {
|
|||
// If the ifindex is zero, interfaceTable returns mappings of all
|
||||
// network interfaces. Otheriwse it returns a mapping of a specific
|
||||
// interface.
|
||||
func interfaceTable(ifindex int) ([]Interface, os.Error) {
|
||||
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||
ai, e := getAdapterList()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
@ -129,7 +129,7 @@ func interfaceTable(ifindex int) ([]Interface, os.Error) {
|
|||
// If the ifindex is zero, interfaceAddrTable returns addresses
|
||||
// for all network interfaces. Otherwise it returns addresses
|
||||
// for a specific interface.
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
||||
ai, e := getAdapterList()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
@ -153,6 +153,6 @@ func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
|
|||
// If the ifindex is zero, interfaceMulticastAddrTable returns
|
||||
// addresses for all network interfaces. Otherwise it returns
|
||||
// addresses for a specific interface.
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, os.Error) {
|
||||
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import "os"
|
||||
|
||||
// IP address lengths (bytes).
|
||||
const (
|
||||
IPv4len = 4
|
||||
|
@ -594,7 +592,7 @@ type ParseError struct {
|
|||
Text string
|
||||
}
|
||||
|
||||
func (e *ParseError) String() string {
|
||||
func (e *ParseError) Error() string {
|
||||
return "invalid " + e.Type + ": " + e.Text
|
||||
}
|
||||
|
||||
|
@ -627,7 +625,7 @@ func ParseIP(s string) IP {
|
|||
// It returns the IP address and the network implied by the IP
|
||||
// and mask. For example, ParseCIDR("192.168.100.1/16") returns
|
||||
// the IP address 192.168.100.1 and the network 192.168.0.0/16.
|
||||
func ParseCIDR(s string) (IP, *IPNet, os.Error) {
|
||||
func ParseCIDR(s string) (IP, *IPNet, error) {
|
||||
i := byteIndex(s, '/')
|
||||
if i < 0 {
|
||||
return nil, nil, &ParseError{"CIDR address", s}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
|
@ -113,7 +112,7 @@ var parsecidrtests = []struct {
|
|||
in string
|
||||
ip IP
|
||||
net *IPNet
|
||||
err os.Error
|
||||
err error
|
||||
}{
|
||||
{"135.104.0.0/32", IPv4(135, 104, 0, 0), &IPNet{IPv4(135, 104, 0, 0), IPv4Mask(255, 255, 255, 255)}, nil},
|
||||
{"0.0.0.0/24", IPv4(0, 0, 0, 0), &IPNet{IPv4(0, 0, 0, 0), IPv4Mask(255, 255, 255, 0)}, nil},
|
||||
|
|
|
@ -71,7 +71,7 @@ func TestICMP(t *testing.T) {
|
|||
|
||||
var (
|
||||
laddr *IPAddr
|
||||
err os.Error
|
||||
err error
|
||||
)
|
||||
if *srchost != "" {
|
||||
laddr, err = ResolveIPAddr("ip4", *srchost)
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// IPAddr represents the address of a IP end point.
|
||||
type IPAddr struct {
|
||||
IP IP
|
||||
|
@ -29,7 +25,7 @@ func (a *IPAddr) String() string {
|
|||
// names to numeric addresses on the network net, which must be
|
||||
// "ip", "ip4" or "ip6". A literal IPv6 host address must be
|
||||
// enclosed in square brackets, as in "[::]".
|
||||
func ResolveIPAddr(net, addr string) (*IPAddr, os.Error) {
|
||||
func ResolveIPAddr(net, addr string) (*IPAddr, error) {
|
||||
ip, err := hostToIP(net, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -38,7 +34,7 @@ func ResolveIPAddr(net, addr string) (*IPAddr, os.Error) {
|
|||
}
|
||||
|
||||
// Convert "host" into IP address.
|
||||
func hostToIP(net, host string) (ip IP, err os.Error) {
|
||||
func hostToIP(net, host string) (ip IP, err error) {
|
||||
var addr IP
|
||||
// Try as an IP address.
|
||||
addr = ParseIP(host)
|
||||
|
|
|
@ -17,17 +17,17 @@ type IPConn bool
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *IPConn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *IPConn) Read(b []byte) (n int, err error) {
|
||||
return 0, os.EPLAN9
|
||||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *IPConn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *IPConn) Write(b []byte) (n int, err error) {
|
||||
return 0, os.EPLAN9
|
||||
}
|
||||
|
||||
// Close closes the IP connection.
|
||||
func (c *IPConn) Close() os.Error {
|
||||
func (c *IPConn) Close() error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
|
@ -42,24 +42,24 @@ func (c *IPConn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *IPConn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *IPConn) SetTimeout(nsec int64) error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *IPConn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *IPConn) SetReadTimeout(nsec int64) error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *IPConn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *IPConn) SetWriteTimeout(nsec int64) error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
// IP-specific methods.
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
||||
func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
err = os.EPLAN9
|
||||
return
|
||||
}
|
||||
|
@ -70,23 +70,23 @@ func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
|||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetWriteTimeout.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (n int, err os.Error) {
|
||||
func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (n int, err error) {
|
||||
return 0, os.EPLAN9
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
||||
func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
return 0, os.EPLAN9
|
||||
}
|
||||
|
||||
func splitNetProto(netProto string) (net string, proto int, err os.Error) {
|
||||
func splitNetProto(netProto string) (net string, proto int, err error) {
|
||||
err = os.EPLAN9
|
||||
return
|
||||
}
|
||||
|
||||
// DialIP connects to the remote address raddr on the network net,
|
||||
// which must be "ip", "ip4", or "ip6".
|
||||
func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err os.Error) {
|
||||
func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,6 @@ func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err os.Error) {
|
|||
// local address laddr. The returned connection c's ReadFrom
|
||||
// and WriteTo methods can be used to receive and send IP
|
||||
// packets with per-packet addressing.
|
||||
func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err os.Error) {
|
||||
func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
@ -33,7 +34,7 @@ func (a *IPAddr) family() int {
|
|||
return syscall.AF_INET6
|
||||
}
|
||||
|
||||
func (a *IPAddr) sockaddr(family int) (syscall.Sockaddr, os.Error) {
|
||||
func (a *IPAddr) sockaddr(family int) (syscall.Sockaddr, error) {
|
||||
return ipToSockaddr(family, a.IP, 0)
|
||||
}
|
||||
|
||||
|
@ -57,13 +58,13 @@ func (c *IPConn) ok() bool { return c != nil && c.fd != nil }
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *IPConn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *IPConn) Read(b []byte) (n int, err error) {
|
||||
n, _, err = c.ReadFrom(b)
|
||||
return
|
||||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *IPConn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *IPConn) Write(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ func (c *IPConn) Write(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Close closes the IP connection.
|
||||
func (c *IPConn) Close() os.Error {
|
||||
func (c *IPConn) Close() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ func (c *IPConn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *IPConn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *IPConn) SetTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ func (c *IPConn) SetTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *IPConn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *IPConn) SetReadTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -113,7 +114,7 @@ func (c *IPConn) SetReadTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *IPConn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *IPConn) SetWriteTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ func (c *IPConn) SetWriteTimeout(nsec int64) os.Error {
|
|||
|
||||
// SetReadBuffer sets the size of the operating system's
|
||||
// receive buffer associated with the connection.
|
||||
func (c *IPConn) SetReadBuffer(bytes int) os.Error {
|
||||
func (c *IPConn) SetReadBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ func (c *IPConn) SetReadBuffer(bytes int) os.Error {
|
|||
|
||||
// SetWriteBuffer sets the size of the operating system's
|
||||
// transmit buffer associated with the connection.
|
||||
func (c *IPConn) SetWriteBuffer(bytes int) os.Error {
|
||||
func (c *IPConn) SetWriteBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -147,7 +148,7 @@ func (c *IPConn) SetWriteBuffer(bytes int) os.Error {
|
|||
// ReadFromIP can be made to time out and return an error with
|
||||
// Timeout() == true after a fixed time limit; see SetTimeout and
|
||||
// SetReadTimeout.
|
||||
func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error) {
|
||||
func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -169,7 +170,7 @@ func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error) {
|
|||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
||||
func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -183,19 +184,19 @@ func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
|||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetWriteTimeout.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (n int, err os.Error) {
|
||||
func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
sa, err1 := addr.sockaddr(c.fd.family)
|
||||
if err1 != nil {
|
||||
return 0, &OpError{Op: "write", Net: "ip", Addr: addr, Error: err1}
|
||||
return 0, &OpError{Op: "write", Net: "ip", Addr: addr, Err: err1}
|
||||
}
|
||||
return c.fd.WriteTo(b, sa)
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
||||
func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -206,10 +207,10 @@ func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
|||
return c.WriteToIP(b, a)
|
||||
}
|
||||
|
||||
func splitNetProto(netProto string) (net string, proto int, err os.Error) {
|
||||
func splitNetProto(netProto string) (net string, proto int, err error) {
|
||||
i := last(netProto, ':')
|
||||
if i < 0 { // no colon
|
||||
return "", 0, os.NewError("no IP protocol specified")
|
||||
return "", 0, errors.New("no IP protocol specified")
|
||||
}
|
||||
net = netProto[0:i]
|
||||
protostr := netProto[i+1:]
|
||||
|
@ -225,7 +226,7 @@ func splitNetProto(netProto string) (net string, proto int, err os.Error) {
|
|||
|
||||
// DialIP connects to the remote address raddr on the network net,
|
||||
// which must be "ip", "ip4", or "ip6".
|
||||
func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err os.Error) {
|
||||
func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err error) {
|
||||
net, proto, err := splitNetProto(netProto)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -249,7 +250,7 @@ func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err os.Error) {
|
|||
// local address laddr. The returned connection c's ReadFrom
|
||||
// and WriteTo methods can be used to receive and send IP
|
||||
// packets with per-packet addressing.
|
||||
func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err os.Error) {
|
||||
func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err error) {
|
||||
net, proto, err := splitNetProto(netProto)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -267,7 +268,7 @@ func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err os.Error) {
|
|||
}
|
||||
|
||||
// BindToDevice binds an IPConn to a network interface.
|
||||
func (c *IPConn) BindToDevice(device string) os.Error {
|
||||
func (c *IPConn) BindToDevice(device string) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -279,4 +280,4 @@ func (c *IPConn) BindToDevice(device string) os.Error {
|
|||
// 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 c does not affect f, and closing f does not affect c.
|
||||
func (c *IPConn) File() (f *os.File, err os.Error) { return c.fd.dup() }
|
||||
func (c *IPConn) File() (f *os.File, err error) { return c.fd.dup() }
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var supportsIPv6, supportsIPv4map = probeIPv6Stack()
|
||||
|
||||
func firstFavoriteAddr(filter func(IP) IP, addrs []string) (addr IP) {
|
||||
|
@ -61,14 +57,14 @@ func ipv6only(x IP) IP {
|
|||
|
||||
type InvalidAddrError string
|
||||
|
||||
func (e InvalidAddrError) String() string { return string(e) }
|
||||
func (e InvalidAddrError) Error() string { return string(e) }
|
||||
func (e InvalidAddrError) Timeout() bool { return false }
|
||||
func (e InvalidAddrError) Temporary() bool { return false }
|
||||
|
||||
// SplitHostPort splits a network address of the form
|
||||
// "host:port" or "[host]:port" into host and port.
|
||||
// The latter form must be used when host contains a colon.
|
||||
func SplitHostPort(hostport string) (host, port string, err os.Error) {
|
||||
func SplitHostPort(hostport string) (host, port string, err error) {
|
||||
// The port starts after the last colon.
|
||||
i := last(hostport, ':')
|
||||
if i < 0 {
|
||||
|
@ -102,7 +98,7 @@ func JoinHostPort(host, port string) string {
|
|||
}
|
||||
|
||||
// Convert "host:port" into IP address and port.
|
||||
func hostPortToIP(net, hostport string) (ip IP, iport int, err os.Error) {
|
||||
func hostPortToIP(net, hostport string) (ip IP, iport int, err error) {
|
||||
var (
|
||||
addr IP
|
||||
p, i int
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -18,7 +20,7 @@ func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
|
|||
}
|
||||
|
||||
// parsePlan9Addr parses address of the form [ip!]port (e.g. 127.0.0.1!80).
|
||||
func parsePlan9Addr(s string) (ip IP, iport int, err os.Error) {
|
||||
func parsePlan9Addr(s string) (ip IP, iport int, err error) {
|
||||
var (
|
||||
addr IP
|
||||
p, i int
|
||||
|
@ -29,13 +31,13 @@ func parsePlan9Addr(s string) (ip IP, iport int, err os.Error) {
|
|||
if i >= 0 {
|
||||
addr = ParseIP(s[:i])
|
||||
if addr == nil {
|
||||
err = os.NewError("net: parsing IP failed")
|
||||
err = errors.New("net: parsing IP failed")
|
||||
goto Error
|
||||
}
|
||||
}
|
||||
p, _, ok = dtoi(s[i+1:], 0)
|
||||
if !ok {
|
||||
err = os.NewError("net: parsing port failed")
|
||||
err = errors.New("net: parsing port failed")
|
||||
goto Error
|
||||
}
|
||||
if p < 0 || p > 0xFFFF {
|
||||
|
@ -48,7 +50,7 @@ Error:
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
func readPlan9Addr(proto, filename string) (addr Addr, err os.Error) {
|
||||
func readPlan9Addr(proto, filename string) (addr Addr, err error) {
|
||||
var buf [128]byte
|
||||
|
||||
f, err := os.Open(filename)
|
||||
|
@ -69,7 +71,7 @@ func readPlan9Addr(proto, filename string) (addr Addr, err os.Error) {
|
|||
case "udp":
|
||||
addr = &UDPAddr{ip, port}
|
||||
default:
|
||||
return nil, os.NewError("unknown protocol " + proto)
|
||||
return nil, errors.New("unknown protocol " + proto)
|
||||
}
|
||||
return addr, nil
|
||||
}
|
||||
|
@ -89,7 +91,7 @@ func (c *plan9Conn) ok() bool { return c != nil && c.ctl != nil }
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *plan9Conn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *plan9Conn) Read(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -100,7 +102,7 @@ func (c *plan9Conn) Read(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
}
|
||||
n, err = c.data.Read(b)
|
||||
if c.proto == "udp" && err == os.EOF {
|
||||
if c.proto == "udp" && err == io.EOF {
|
||||
n = 0
|
||||
err = nil
|
||||
}
|
||||
|
@ -108,7 +110,7 @@ func (c *plan9Conn) Read(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *plan9Conn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *plan9Conn) Write(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -122,7 +124,7 @@ func (c *plan9Conn) Write(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Close closes the connection.
|
||||
func (c *plan9Conn) Close() os.Error {
|
||||
func (c *plan9Conn) Close() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -155,7 +157,7 @@ func (c *plan9Conn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *plan9Conn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *plan9Conn) SetTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -163,7 +165,7 @@ func (c *plan9Conn) SetTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *plan9Conn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *plan9Conn) SetReadTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -171,14 +173,14 @@ func (c *plan9Conn) SetReadTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *plan9Conn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *plan9Conn) SetWriteTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
func startPlan9(net string, addr Addr) (ctl *os.File, dest, proto, name string, err os.Error) {
|
||||
func startPlan9(net string, addr Addr) (ctl *os.File, dest, proto, name string, err error) {
|
||||
var (
|
||||
ip IP
|
||||
port int
|
||||
|
@ -213,7 +215,7 @@ func startPlan9(net string, addr Addr) (ctl *os.File, dest, proto, name string,
|
|||
return f, dest, proto, string(buf[:n]), nil
|
||||
}
|
||||
|
||||
func dialPlan9(net string, laddr, raddr Addr) (c *plan9Conn, err os.Error) {
|
||||
func dialPlan9(net string, laddr, raddr Addr) (c *plan9Conn, err error) {
|
||||
f, dest, proto, name, err := startPlan9(net, raddr)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -239,7 +241,7 @@ type plan9Listener struct {
|
|||
laddr Addr
|
||||
}
|
||||
|
||||
func listenPlan9(net string, laddr Addr) (l *plan9Listener, err os.Error) {
|
||||
func listenPlan9(net string, laddr Addr) (l *plan9Listener, err error) {
|
||||
f, dest, proto, name, err := startPlan9(net, laddr)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -265,7 +267,7 @@ func (l *plan9Listener) plan9Conn() *plan9Conn {
|
|||
return newPlan9Conn(l.proto, l.name, l.ctl, l.laddr, nil)
|
||||
}
|
||||
|
||||
func (l *plan9Listener) acceptPlan9() (c *plan9Conn, err os.Error) {
|
||||
func (l *plan9Listener) acceptPlan9() (c *plan9Conn, err error) {
|
||||
f, err := os.Open(l.dir + "/listen")
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -287,7 +289,7 @@ func (l *plan9Listener) acceptPlan9() (c *plan9Conn, err os.Error) {
|
|||
return newPlan9Conn(l.proto, name, f, laddr, raddr), nil
|
||||
}
|
||||
|
||||
func (l *plan9Listener) Accept() (c Conn, err os.Error) {
|
||||
func (l *plan9Listener) Accept() (c Conn, err error) {
|
||||
c1, err := l.acceptPlan9()
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -295,7 +297,7 @@ func (l *plan9Listener) Accept() (c Conn, err os.Error) {
|
|||
return c1, nil
|
||||
}
|
||||
|
||||
func (l *plan9Listener) Close() os.Error {
|
||||
func (l *plan9Listener) Close() error {
|
||||
if l == nil || l.ctl == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
import "syscall"
|
||||
|
||||
// Should we try to use the IPv4 socket interface if we're
|
||||
// only dealing with IPv4 sockets? As long as the host system
|
||||
|
@ -105,12 +102,12 @@ func listenBacklog() int { return syscall.SOMAXCONN }
|
|||
// be converted into a syscall.Sockaddr.
|
||||
type sockaddr interface {
|
||||
Addr
|
||||
sockaddr(family int) (syscall.Sockaddr, os.Error)
|
||||
sockaddr(family int) (syscall.Sockaddr, error)
|
||||
family() int
|
||||
}
|
||||
|
||||
func internetSocket(net string, laddr, raddr sockaddr, socktype, proto int, mode string, toAddr func(syscall.Sockaddr) Addr) (fd *netFD, err os.Error) {
|
||||
var oserr os.Error
|
||||
func internetSocket(net string, laddr, raddr sockaddr, socktype, proto int, mode string, toAddr func(syscall.Sockaddr) Addr) (fd *netFD, err error) {
|
||||
var oserr error
|
||||
var la, ra syscall.Sockaddr
|
||||
family := favoriteAddrFamily(net, raddr, laddr, mode)
|
||||
if laddr != nil {
|
||||
|
@ -137,7 +134,7 @@ Error:
|
|||
return nil, &OpError{mode, net, addr, oserr}
|
||||
}
|
||||
|
||||
func ipToSockaddr(family int, ip IP, port int) (syscall.Sockaddr, os.Error) {
|
||||
func ipToSockaddr(family int, ip IP, port int) (syscall.Sockaddr, error) {
|
||||
switch family {
|
||||
case syscall.AF_INET:
|
||||
if len(ip) == 0 {
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
func query(filename, query string, bufSize int) (res []string, err os.Error) {
|
||||
func query(filename, query string, bufSize int) (res []string, err error) {
|
||||
file, err := os.OpenFile(filename, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -34,7 +35,7 @@ func query(filename, query string, bufSize int) (res []string, err os.Error) {
|
|||
return
|
||||
}
|
||||
|
||||
func queryCS(net, host, service string) (res []string, err os.Error) {
|
||||
func queryCS(net, host, service string) (res []string, err error) {
|
||||
switch net {
|
||||
case "tcp4", "tcp6":
|
||||
net = "tcp"
|
||||
|
@ -47,7 +48,7 @@ func queryCS(net, host, service string) (res []string, err os.Error) {
|
|||
return query("/net/cs", net+"!"+host+"!"+service, 128)
|
||||
}
|
||||
|
||||
func queryCS1(net string, ip IP, port int) (clone, dest string, err os.Error) {
|
||||
func queryCS1(net string, ip IP, port int) (clone, dest string, err error) {
|
||||
ips := "*"
|
||||
if len(ip) != 0 && !ip.IsUnspecified() {
|
||||
ips = ip.String()
|
||||
|
@ -58,19 +59,19 @@ func queryCS1(net string, ip IP, port int) (clone, dest string, err os.Error) {
|
|||
}
|
||||
f := getFields(lines[0])
|
||||
if len(f) < 2 {
|
||||
return "", "", os.NewError("net: bad response from ndb/cs")
|
||||
return "", "", errors.New("net: bad response from ndb/cs")
|
||||
}
|
||||
clone, dest = f[0], f[1]
|
||||
return
|
||||
}
|
||||
|
||||
func queryDNS(addr string, typ string) (res []string, err os.Error) {
|
||||
func queryDNS(addr string, typ string) (res []string, err error) {
|
||||
return query("/net/dns", addr+" "+typ, 1024)
|
||||
}
|
||||
|
||||
// LookupHost looks up the given host using the local resolver.
|
||||
// It returns an array of that host's addresses.
|
||||
func LookupHost(host string) (addrs []string, err os.Error) {
|
||||
func LookupHost(host string) (addrs []string, err error) {
|
||||
// Use /net/cs insead of /net/dns because cs knows about
|
||||
// host names in local network (e.g. from /lib/ndb/local)
|
||||
lines, err := queryCS("tcp", host, "1")
|
||||
|
@ -96,7 +97,7 @@ func LookupHost(host string) (addrs []string, err os.Error) {
|
|||
|
||||
// LookupIP looks up host using the local resolver.
|
||||
// It returns an array of that host's IPv4 and IPv6 addresses.
|
||||
func LookupIP(host string) (ips []IP, err os.Error) {
|
||||
func LookupIP(host string) (ips []IP, err error) {
|
||||
addrs, err := LookupHost(host)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -110,7 +111,7 @@ func LookupIP(host string) (ips []IP, err os.Error) {
|
|||
}
|
||||
|
||||
// LookupPort looks up the port for the given network and service.
|
||||
func LookupPort(network, service string) (port int, err os.Error) {
|
||||
func LookupPort(network, service string) (port int, err error) {
|
||||
switch network {
|
||||
case "tcp4", "tcp6":
|
||||
network = "tcp"
|
||||
|
@ -143,7 +144,7 @@ func LookupPort(network, service string) (port int, err os.Error) {
|
|||
// Callers that do not care about the canonical name can call
|
||||
// LookupHost or LookupIP directly; both take care of resolving
|
||||
// the canonical name as part of the lookup.
|
||||
func LookupCNAME(name string) (cname string, err os.Error) {
|
||||
func LookupCNAME(name string) (cname string, err error) {
|
||||
lines, err := queryDNS(name, "cname")
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -153,7 +154,7 @@ func LookupCNAME(name string) (cname string, err os.Error) {
|
|||
return f[2] + ".", nil
|
||||
}
|
||||
}
|
||||
return "", os.NewError("net: bad response from ndb/dns")
|
||||
return "", errors.New("net: bad response from ndb/dns")
|
||||
}
|
||||
|
||||
// LookupSRV tries to resolve an SRV query of the given service,
|
||||
|
@ -165,7 +166,7 @@ func LookupCNAME(name string) (cname string, err os.Error) {
|
|||
// That is, it looks up _service._proto.name. To accommodate services
|
||||
// publishing SRV records under non-standard names, if both service
|
||||
// and proto are empty strings, LookupSRV looks up name directly.
|
||||
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error) {
|
||||
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err error) {
|
||||
var target string
|
||||
if service == "" && proto == "" {
|
||||
target = name
|
||||
|
@ -195,7 +196,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.
|
|||
}
|
||||
|
||||
// LookupMX returns the DNS MX records for the given domain name sorted by preference.
|
||||
func LookupMX(name string) (mx []*MX, err os.Error) {
|
||||
func LookupMX(name string) (mx []*MX, err error) {
|
||||
lines, err := queryDNS(name, "mx")
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -214,7 +215,7 @@ func LookupMX(name string) (mx []*MX, err os.Error) {
|
|||
}
|
||||
|
||||
// LookupTXT returns the DNS TXT records for the given domain name.
|
||||
func LookupTXT(name string) (txt []string, err os.Error) {
|
||||
func LookupTXT(name string) (txt []string, err error) {
|
||||
lines, err := queryDNS(name, "txt")
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -229,7 +230,7 @@ func LookupTXT(name string) (txt []string, err os.Error) {
|
|||
|
||||
// LookupAddr performs a reverse lookup for the given address, returning a list
|
||||
// of names mapping to that address.
|
||||
func LookupAddr(addr string) (name []string, err os.Error) {
|
||||
func LookupAddr(addr string) (name []string, err error) {
|
||||
arpa, err := reverseaddr(addr)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
"errors"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -43,18 +43,18 @@ func readProtocols() {
|
|||
|
||||
// lookupProtocol looks up IP protocol name in /etc/protocols and
|
||||
// returns correspondent protocol number.
|
||||
func lookupProtocol(name string) (proto int, err os.Error) {
|
||||
func lookupProtocol(name string) (proto int, err error) {
|
||||
onceReadProtocols.Do(readProtocols)
|
||||
proto, found := protocols[name]
|
||||
if !found {
|
||||
return 0, os.NewError("unknown IP protocol specified: " + name)
|
||||
return 0, errors.New("unknown IP protocol specified: " + name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LookupHost looks up the given host using the local resolver.
|
||||
// It returns an array of that host's addresses.
|
||||
func LookupHost(host string) (addrs []string, err os.Error) {
|
||||
func LookupHost(host string) (addrs []string, err error) {
|
||||
addrs, err, ok := cgoLookupHost(host)
|
||||
if !ok {
|
||||
addrs, err = goLookupHost(host)
|
||||
|
@ -64,7 +64,7 @@ func LookupHost(host string) (addrs []string, err os.Error) {
|
|||
|
||||
// LookupIP looks up host using the local resolver.
|
||||
// It returns an array of that host's IPv4 and IPv6 addresses.
|
||||
func LookupIP(host string) (addrs []IP, err os.Error) {
|
||||
func LookupIP(host string) (addrs []IP, err error) {
|
||||
addrs, err, ok := cgoLookupIP(host)
|
||||
if !ok {
|
||||
addrs, err = goLookupIP(host)
|
||||
|
@ -73,7 +73,7 @@ func LookupIP(host string) (addrs []IP, err os.Error) {
|
|||
}
|
||||
|
||||
// LookupPort looks up the port for the given network and service.
|
||||
func LookupPort(network, service string) (port int, err os.Error) {
|
||||
func LookupPort(network, service string) (port int, err error) {
|
||||
port, err, ok := cgoLookupPort(network, service)
|
||||
if !ok {
|
||||
port, err = goLookupPort(network, service)
|
||||
|
@ -85,7 +85,7 @@ func LookupPort(network, service string) (port int, err os.Error) {
|
|||
// Callers that do not care about the canonical name can call
|
||||
// LookupHost or LookupIP directly; both take care of resolving
|
||||
// the canonical name as part of the lookup.
|
||||
func LookupCNAME(name string) (cname string, err os.Error) {
|
||||
func LookupCNAME(name string) (cname string, err error) {
|
||||
cname, err, ok := cgoLookupCNAME(name)
|
||||
if !ok {
|
||||
cname, err = goLookupCNAME(name)
|
||||
|
@ -102,7 +102,7 @@ func LookupCNAME(name string) (cname string, err os.Error) {
|
|||
// That is, it looks up _service._proto.name. To accommodate services
|
||||
// publishing SRV records under non-standard names, if both service
|
||||
// and proto are empty strings, LookupSRV looks up name directly.
|
||||
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error) {
|
||||
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err error) {
|
||||
var target string
|
||||
if service == "" && proto == "" {
|
||||
target = name
|
||||
|
@ -124,7 +124,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.
|
|||
}
|
||||
|
||||
// LookupMX returns the DNS MX records for the given domain name sorted by preference.
|
||||
func LookupMX(name string) (mx []*MX, err os.Error) {
|
||||
func LookupMX(name string) (mx []*MX, err error) {
|
||||
_, records, err := lookup(name, dnsTypeMX)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -139,7 +139,7 @@ func LookupMX(name string) (mx []*MX, err os.Error) {
|
|||
}
|
||||
|
||||
// LookupTXT returns the DNS TXT records for the given domain name.
|
||||
func LookupTXT(name string) (txt []string, err os.Error) {
|
||||
func LookupTXT(name string) (txt []string, err error) {
|
||||
_, records, err := lookup(name, dnsTypeTXT)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -153,7 +153,7 @@ func LookupTXT(name string) (txt []string, err os.Error) {
|
|||
|
||||
// LookupAddr performs a reverse lookup for the given address, returning a list
|
||||
// of names mapping to that address.
|
||||
func LookupAddr(addr string) (name []string, err os.Error) {
|
||||
func LookupAddr(addr string) (name []string, err error) {
|
||||
name = lookupStaticAddr(addr)
|
||||
if len(name) > 0 {
|
||||
return
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"os"
|
||||
|
@ -18,7 +19,7 @@ var (
|
|||
)
|
||||
|
||||
// lookupProtocol looks up IP protocol name and returns correspondent protocol number.
|
||||
func lookupProtocol(name string) (proto int, err os.Error) {
|
||||
func lookupProtocol(name string) (proto int, err error) {
|
||||
protoentLock.Lock()
|
||||
defer protoentLock.Unlock()
|
||||
p, e := syscall.GetProtoByName(name)
|
||||
|
@ -28,7 +29,7 @@ func lookupProtocol(name string) (proto int, err os.Error) {
|
|||
return int(p.Proto), nil
|
||||
}
|
||||
|
||||
func LookupHost(name string) (addrs []string, err os.Error) {
|
||||
func LookupHost(name string) (addrs []string, err error) {
|
||||
ips, err := LookupIP(name)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -40,7 +41,7 @@ func LookupHost(name string) (addrs []string, err os.Error) {
|
|||
return
|
||||
}
|
||||
|
||||
func LookupIP(name string) (addrs []IP, err os.Error) {
|
||||
func LookupIP(name string) (addrs []IP, err error) {
|
||||
hostentLock.Lock()
|
||||
defer hostentLock.Unlock()
|
||||
h, e := syscall.GetHostByName(name)
|
||||
|
@ -61,7 +62,7 @@ func LookupIP(name string) (addrs []IP, err os.Error) {
|
|||
return addrs, nil
|
||||
}
|
||||
|
||||
func LookupPort(network, service string) (port int, err os.Error) {
|
||||
func LookupPort(network, service string) (port int, err error) {
|
||||
switch network {
|
||||
case "tcp4", "tcp6":
|
||||
network = "tcp"
|
||||
|
@ -77,7 +78,7 @@ func LookupPort(network, service string) (port int, err os.Error) {
|
|||
return int(syscall.Ntohs(s.Port)), nil
|
||||
}
|
||||
|
||||
func LookupCNAME(name string) (cname string, err os.Error) {
|
||||
func LookupCNAME(name string) (cname string, err error) {
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil)
|
||||
if int(e) != 0 {
|
||||
|
@ -100,7 +101,7 @@ func LookupCNAME(name string) (cname string, err os.Error) {
|
|||
// That is, it looks up _service._proto.name. To accommodate services
|
||||
// publishing SRV records under non-standard names, if both service
|
||||
// and proto are empty strings, LookupSRV looks up name directly.
|
||||
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error) {
|
||||
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err error) {
|
||||
var target string
|
||||
if service == "" && proto == "" {
|
||||
target = name
|
||||
|
@ -122,7 +123,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.
|
|||
return name, addrs, nil
|
||||
}
|
||||
|
||||
func LookupMX(name string) (mx []*MX, err os.Error) {
|
||||
func LookupMX(name string) (mx []*MX, err error) {
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil)
|
||||
if int(e) != 0 {
|
||||
|
@ -138,11 +139,11 @@ func LookupMX(name string) (mx []*MX, err os.Error) {
|
|||
return mx, nil
|
||||
}
|
||||
|
||||
func LookupTXT(name string) (txt []string, err os.Error) {
|
||||
return nil, os.NewError("net.LookupTXT is not implemented on Windows")
|
||||
func LookupTXT(name string) (txt []string, err error) {
|
||||
return nil, errors.New("net.LookupTXT is not implemented on Windows")
|
||||
}
|
||||
|
||||
func LookupAddr(addr string) (name []string, err os.Error) {
|
||||
func LookupAddr(addr string) (name []string, err error) {
|
||||
arpa, err := reverseaddr(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -9,7 +9,7 @@ package net
|
|||
// TODO(rsc):
|
||||
// support for raw ethernet sockets
|
||||
|
||||
import "os"
|
||||
import "errors"
|
||||
|
||||
// Addr represents a network end point address.
|
||||
type Addr interface {
|
||||
|
@ -22,15 +22,15 @@ type Conn interface {
|
|||
// Read reads data from the connection.
|
||||
// Read can be made to time out and return a net.Error with Timeout() == true
|
||||
// after a fixed time limit; see SetTimeout and SetReadTimeout.
|
||||
Read(b []byte) (n int, err os.Error)
|
||||
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
|
||||
// after a fixed time limit; see SetTimeout and SetWriteTimeout.
|
||||
Write(b []byte) (n int, err os.Error)
|
||||
Write(b []byte) (n int, err error)
|
||||
|
||||
// Close closes the connection.
|
||||
Close() os.Error
|
||||
Close() error
|
||||
|
||||
// LocalAddr returns the local network address.
|
||||
LocalAddr() Addr
|
||||
|
@ -40,24 +40,24 @@ type Conn interface {
|
|||
|
||||
// SetTimeout sets the read and write deadlines associated
|
||||
// with the connection.
|
||||
SetTimeout(nsec int64) os.Error
|
||||
SetTimeout(nsec int64) error
|
||||
|
||||
// SetReadTimeout sets the time (in nanoseconds) that
|
||||
// Read will wait for data before returning an error with Timeout() == true.
|
||||
// Setting nsec == 0 (the default) disables the deadline.
|
||||
SetReadTimeout(nsec int64) os.Error
|
||||
SetReadTimeout(nsec int64) error
|
||||
|
||||
// SetWriteTimeout sets the time (in nanoseconds) that
|
||||
// Write will wait to send its data before returning an error with Timeout() == true.
|
||||
// Setting nsec == 0 (the default) disables the deadline.
|
||||
// Even if write times out, it may return n > 0, indicating that
|
||||
// some of the data was successfully written.
|
||||
SetWriteTimeout(nsec int64) os.Error
|
||||
SetWriteTimeout(nsec int64) error
|
||||
}
|
||||
|
||||
// An Error represents a network error.
|
||||
type Error interface {
|
||||
os.Error
|
||||
error
|
||||
Timeout() bool // Is the error a timeout?
|
||||
Temporary() bool // Is the error temporary?
|
||||
}
|
||||
|
@ -71,60 +71,60 @@ type PacketConn interface {
|
|||
// ReadFrom can be made to time out and return
|
||||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetReadTimeout.
|
||||
ReadFrom(b []byte) (n int, addr Addr, err os.Error)
|
||||
ReadFrom(b []byte) (n int, addr Addr, err error)
|
||||
|
||||
// WriteTo writes a packet with payload b to addr.
|
||||
// WriteTo can be made to time out and return
|
||||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetWriteTimeout.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
WriteTo(b []byte, addr Addr) (n int, err os.Error)
|
||||
WriteTo(b []byte, addr Addr) (n int, err error)
|
||||
|
||||
// Close closes the connection.
|
||||
Close() os.Error
|
||||
Close() error
|
||||
|
||||
// LocalAddr returns the local network address.
|
||||
LocalAddr() Addr
|
||||
|
||||
// SetTimeout sets the read and write deadlines associated
|
||||
// with the connection.
|
||||
SetTimeout(nsec int64) os.Error
|
||||
SetTimeout(nsec int64) error
|
||||
|
||||
// SetReadTimeout sets the time (in nanoseconds) that
|
||||
// Read will wait for data before returning an error with Timeout() == true.
|
||||
// Setting nsec == 0 (the default) disables the deadline.
|
||||
SetReadTimeout(nsec int64) os.Error
|
||||
SetReadTimeout(nsec int64) error
|
||||
|
||||
// SetWriteTimeout sets the time (in nanoseconds) that
|
||||
// Write will wait to send its data before returning an error with Timeout() == true.
|
||||
// Setting nsec == 0 (the default) disables the deadline.
|
||||
// Even if write times out, it may return n > 0, indicating that
|
||||
// some of the data was successfully written.
|
||||
SetWriteTimeout(nsec int64) os.Error
|
||||
SetWriteTimeout(nsec int64) error
|
||||
}
|
||||
|
||||
// A Listener is a generic network listener for stream-oriented protocols.
|
||||
type Listener interface {
|
||||
// Accept waits for and returns the next connection to the listener.
|
||||
Accept() (c Conn, err os.Error)
|
||||
Accept() (c Conn, err error)
|
||||
|
||||
// Close closes the listener.
|
||||
Close() os.Error
|
||||
Close() error
|
||||
|
||||
// Addr returns the listener's network address.
|
||||
Addr() Addr
|
||||
}
|
||||
|
||||
var errMissingAddress = os.NewError("missing address")
|
||||
var errMissingAddress = errors.New("missing address")
|
||||
|
||||
type OpError struct {
|
||||
Op string
|
||||
Net string
|
||||
Addr Addr
|
||||
Error os.Error
|
||||
Op string
|
||||
Net string
|
||||
Addr Addr
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *OpError) String() string {
|
||||
func (e *OpError) Error() string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func (e *OpError) String() string {
|
|||
if e.Addr != nil {
|
||||
s += " " + e.Addr.String()
|
||||
}
|
||||
s += ": " + e.Error.String()
|
||||
s += ": " + e.Err.Error()
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ type temporary interface {
|
|||
}
|
||||
|
||||
func (e *OpError) Temporary() bool {
|
||||
t, ok := e.Error.(temporary)
|
||||
t, ok := e.Err.(temporary)
|
||||
return ok && t.Temporary()
|
||||
}
|
||||
|
||||
|
@ -153,20 +153,20 @@ type timeout interface {
|
|||
}
|
||||
|
||||
func (e *OpError) Timeout() bool {
|
||||
t, ok := e.Error.(timeout)
|
||||
t, ok := e.Err.(timeout)
|
||||
return ok && t.Timeout()
|
||||
}
|
||||
|
||||
type AddrError struct {
|
||||
Error string
|
||||
Addr string
|
||||
Err string
|
||||
Addr string
|
||||
}
|
||||
|
||||
func (e *AddrError) String() string {
|
||||
func (e *AddrError) Error() string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
s := e.Error
|
||||
s := e.Err
|
||||
if e.Addr != "" {
|
||||
s += " " + e.Addr
|
||||
}
|
||||
|
@ -183,6 +183,6 @@ func (e *AddrError) Timeout() bool {
|
|||
|
||||
type UnknownNetworkError string
|
||||
|
||||
func (e UnknownNetworkError) String() string { return "unknown network " + string(e) }
|
||||
func (e UnknownNetworkError) Error() string { return "unknown network " + string(e) }
|
||||
func (e UnknownNetworkError) Temporary() bool { return false }
|
||||
func (e UnknownNetworkError) Timeout() bool { return false }
|
||||
|
|
|
@ -6,7 +6,7 @@ package net
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"io"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
@ -79,7 +79,7 @@ func TestDialError(t *testing.T) {
|
|||
t.Errorf("#%d: nil error, want match for %#q", i, tt.Pattern)
|
||||
continue
|
||||
}
|
||||
s := e.String()
|
||||
s := e.Error()
|
||||
match, _ := regexp.MatchString(tt.Pattern, s)
|
||||
if !match {
|
||||
t.Errorf("#%d: %q, want match for %#q", i, s, tt.Pattern)
|
||||
|
@ -119,8 +119,8 @@ func TestReverseAddress(t *testing.T) {
|
|||
if len(tt.ErrPrefix) == 0 && e != nil {
|
||||
t.Errorf("#%d: expected <nil>, got %q (error)", i, e)
|
||||
}
|
||||
if e != nil && e.(*DNSError).Error != tt.ErrPrefix {
|
||||
t.Errorf("#%d: expected %q, got %q (mismatched error)", i, tt.ErrPrefix, e.(*DNSError).Error)
|
||||
if e != nil && e.(*DNSError).Err != tt.ErrPrefix {
|
||||
t.Errorf("#%d: expected %q, got %q (mismatched error)", i, tt.ErrPrefix, e.(*DNSError).Err)
|
||||
}
|
||||
if a != tt.Reverse {
|
||||
t.Errorf("#%d: expected %q, got %q (reverse address)", i, tt.Reverse, a)
|
||||
|
@ -146,7 +146,7 @@ func TestShutdown(t *testing.T) {
|
|||
}
|
||||
var buf [10]byte
|
||||
n, err := c.Read(buf[:])
|
||||
if n != 0 || err != os.EOF {
|
||||
if n != 0 || err != io.EOF {
|
||||
t.Fatalf("server Read = %d, %v; want 0, os.EOF", n, err)
|
||||
}
|
||||
c.Write([]byte("response"))
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func newPollServer() (s *pollServer, err os.Error) {
|
||||
func newPollServer() (s *pollServer, err error) {
|
||||
s = new(pollServer)
|
||||
s.cr = make(chan *netFD, 1)
|
||||
s.cw = make(chan *netFD, 1)
|
||||
|
|
|
@ -54,7 +54,7 @@ func (f *file) readLine() (s string, ok bool) {
|
|||
if n >= 0 {
|
||||
f.data = f.data[0 : ln+n]
|
||||
}
|
||||
if err == os.EOF {
|
||||
if err == io.EOF {
|
||||
f.atEOF = true
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func (f *file) readLine() (s string, ok bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func open(name string) (*file, os.Error) {
|
||||
func open(name string) (*file, error) {
|
||||
fd, err := os.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Pipe creates a synchronous, in-memory, full duplex
|
||||
|
@ -32,7 +32,7 @@ func (pipeAddr) String() string {
|
|||
return "pipe"
|
||||
}
|
||||
|
||||
func (p *pipe) Close() os.Error {
|
||||
func (p *pipe) Close() error {
|
||||
err := p.PipeReader.Close()
|
||||
err1 := p.PipeWriter.Close()
|
||||
if err == nil {
|
||||
|
@ -49,14 +49,14 @@ func (p *pipe) RemoteAddr() Addr {
|
|||
return pipeAddr(0)
|
||||
}
|
||||
|
||||
func (p *pipe) SetTimeout(nsec int64) os.Error {
|
||||
return os.NewError("net.Pipe does not support timeouts")
|
||||
func (p *pipe) SetTimeout(nsec int64) error {
|
||||
return errors.New("net.Pipe does not support timeouts")
|
||||
}
|
||||
|
||||
func (p *pipe) SetReadTimeout(nsec int64) os.Error {
|
||||
return os.NewError("net.Pipe does not support timeouts")
|
||||
func (p *pipe) SetReadTimeout(nsec int64) error {
|
||||
return errors.New("net.Pipe does not support timeouts")
|
||||
}
|
||||
|
||||
func (p *pipe) SetWriteTimeout(nsec int64) os.Error {
|
||||
return os.NewError("net.Pipe does not support timeouts")
|
||||
func (p *pipe) SetWriteTimeout(nsec int64) error {
|
||||
return errors.New("net.Pipe does not support timeouts")
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package net
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -22,7 +21,7 @@ func checkWrite(t *testing.T, w io.Writer, data []byte, c chan int) {
|
|||
c <- 0
|
||||
}
|
||||
|
||||
func checkRead(t *testing.T, r io.Reader, data []byte, wantErr os.Error) {
|
||||
func checkRead(t *testing.T, r io.Reader, data []byte, wantErr error) {
|
||||
buf := make([]byte, len(data)+10)
|
||||
n, err := r.Read(buf)
|
||||
if err != wantErr {
|
||||
|
@ -52,6 +51,6 @@ func TestPipe(t *testing.T) {
|
|||
checkRead(t, srv, []byte("a third line"), nil)
|
||||
<-c
|
||||
go srv.Close()
|
||||
checkRead(t, cli, nil, os.EOF)
|
||||
checkRead(t, cli, nil, io.EOF)
|
||||
cli.Close()
|
||||
}
|
||||
|
|
|
@ -8,13 +8,10 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
import "sync"
|
||||
|
||||
var services map[string]map[string]int
|
||||
var servicesError os.Error
|
||||
var servicesError error
|
||||
var onceReadServices sync.Once
|
||||
|
||||
func readServices() {
|
||||
|
@ -53,7 +50,7 @@ func readServices() {
|
|||
}
|
||||
|
||||
// goLookupPort is the native Go implementation of LookupPort.
|
||||
func goLookupPort(network, service string) (port int, err os.Error) {
|
||||
func goLookupPort(network, service string) (port int, err error) {
|
||||
onceReadServices.Do(readServices)
|
||||
|
||||
switch network {
|
||||
|
|
|
@ -21,7 +21,7 @@ const maxSendfileSize int = 4 << 20
|
|||
// non-EOF error.
|
||||
//
|
||||
// if handled == false, sendFile performed no work.
|
||||
func sendFile(c *netFD, r io.Reader) (written int64, err os.Error, handled bool) {
|
||||
func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
|
||||
var remain int64 = 1 << 62 // by default, copy until EOF
|
||||
|
||||
lr, ok := r.(*io.LimitedReader)
|
||||
|
|
|
@ -6,11 +6,8 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
import "io"
|
||||
|
||||
func sendFile(c *netFD, r io.Reader) (n int64, err os.Error, handled bool) {
|
||||
func sendFile(c *netFD, r io.Reader) (n int64, err error, handled bool) {
|
||||
return 0, nil, false
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (o *sendfileOp) Name() string {
|
|||
// if handled == false, sendFile performed no work.
|
||||
//
|
||||
// Note that sendfile for windows does not suppport >2GB file.
|
||||
func sendFile(c *netFD, r io.Reader) (written int64, err os.Error, handled bool) {
|
||||
func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
|
||||
var n int64 = 0 // by default, copy until EOF
|
||||
|
||||
lr, ok := r.(*io.LimitedReader)
|
||||
|
|
|
@ -55,7 +55,7 @@ func runServe(t *testing.T, network, addr string, listening chan<- string, done
|
|||
|
||||
func connect(t *testing.T, network, addr string, isEmpty bool) {
|
||||
var fd Conn
|
||||
var err os.Error
|
||||
var err error
|
||||
if network == "unixgram" {
|
||||
fd, err = DialUnix(network, &UnixAddr{addr + ".local", network}, &UnixAddr{addr, network})
|
||||
} else {
|
||||
|
|
|
@ -24,7 +24,7 @@ func boolint(b bool) int {
|
|||
}
|
||||
|
||||
// Generic socket creation.
|
||||
func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscall.Sockaddr) Addr) (fd *netFD, err os.Error) {
|
||||
func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscall.Sockaddr) Addr) (fd *netFD, err error) {
|
||||
// See ../syscall/exec.go for description of ForkLock.
|
||||
syscall.ForkLock.RLock()
|
||||
s, e := syscall.Socket(f, p, t)
|
||||
|
@ -67,74 +67,74 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal
|
|||
return fd, nil
|
||||
}
|
||||
|
||||
func setsockoptInt(fd *netFD, level, opt int, value int) os.Error {
|
||||
func setsockoptInt(fd *netFD, level, opt int, value int) error {
|
||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, level, opt, value))
|
||||
}
|
||||
|
||||
func setsockoptNsec(fd *netFD, level, opt int, nsec int64) os.Error {
|
||||
func setsockoptNsec(fd *netFD, level, opt int, nsec int64) error {
|
||||
var tv = syscall.NsecToTimeval(nsec)
|
||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptTimeval(fd.sysfd, level, opt, &tv))
|
||||
}
|
||||
|
||||
func setReadBuffer(fd *netFD, bytes int) os.Error {
|
||||
func setReadBuffer(fd *netFD, bytes int) error {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
return setsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_RCVBUF, bytes)
|
||||
}
|
||||
|
||||
func setWriteBuffer(fd *netFD, bytes int) os.Error {
|
||||
func setWriteBuffer(fd *netFD, bytes int) error {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
return setsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_SNDBUF, bytes)
|
||||
}
|
||||
|
||||
func setReadTimeout(fd *netFD, nsec int64) os.Error {
|
||||
func setReadTimeout(fd *netFD, nsec int64) error {
|
||||
fd.rdeadline_delta = nsec
|
||||
return nil
|
||||
}
|
||||
|
||||
func setWriteTimeout(fd *netFD, nsec int64) os.Error {
|
||||
func setWriteTimeout(fd *netFD, nsec int64) error {
|
||||
fd.wdeadline_delta = nsec
|
||||
return nil
|
||||
}
|
||||
|
||||
func setTimeout(fd *netFD, nsec int64) os.Error {
|
||||
func setTimeout(fd *netFD, nsec int64) error {
|
||||
if e := setReadTimeout(fd, nsec); e != nil {
|
||||
return e
|
||||
}
|
||||
return setWriteTimeout(fd, nsec)
|
||||
}
|
||||
|
||||
func setReuseAddr(fd *netFD, reuse bool) os.Error {
|
||||
func setReuseAddr(fd *netFD, reuse bool) error {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
return setsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, boolint(reuse))
|
||||
}
|
||||
|
||||
func bindToDevice(fd *netFD, dev string) os.Error {
|
||||
func bindToDevice(fd *netFD, dev string) error {
|
||||
// TODO(rsc): call setsockopt with null-terminated string pointer
|
||||
return os.EINVAL
|
||||
}
|
||||
|
||||
func setDontRoute(fd *netFD, dontroute bool) os.Error {
|
||||
func setDontRoute(fd *netFD, dontroute bool) error {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
return setsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_DONTROUTE, boolint(dontroute))
|
||||
}
|
||||
|
||||
func setKeepAlive(fd *netFD, keepalive bool) os.Error {
|
||||
func setKeepAlive(fd *netFD, keepalive bool) error {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
return setsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, boolint(keepalive))
|
||||
}
|
||||
|
||||
func setNoDelay(fd *netFD, noDelay bool) os.Error {
|
||||
func setNoDelay(fd *netFD, noDelay bool) error {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
return setsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, boolint(noDelay))
|
||||
}
|
||||
|
||||
func setLinger(fd *netFD, sec int) os.Error {
|
||||
func setLinger(fd *netFD, sec int) error {
|
||||
var l syscall.Linger
|
||||
if sec >= 0 {
|
||||
l.Onoff = 1
|
||||
|
@ -153,7 +153,7 @@ type UnknownSocketError struct {
|
|||
sa syscall.Sockaddr
|
||||
}
|
||||
|
||||
func (e *UnknownSocketError) String() string {
|
||||
func (e *UnknownSocketError) Error() string {
|
||||
return "unknown socket address type " + reflect.TypeOf(e.sa).String()
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ type writerOnly struct {
|
|||
|
||||
// Fallback implementation of io.ReaderFrom's ReadFrom, when sendfile isn't
|
||||
// applicable.
|
||||
func genericReadFrom(w io.Writer, r io.Reader) (n int64, err os.Error) {
|
||||
func genericReadFrom(w io.Writer, r io.Reader) (n int64, err error) {
|
||||
// Use wrapper to hide existing r.ReadFrom from io.Copy.
|
||||
return io.Copy(writerOnly{w}, r)
|
||||
}
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// TCPAddr represents the address of a TCP end point.
|
||||
type TCPAddr struct {
|
||||
IP IP
|
||||
|
@ -31,7 +27,7 @@ func (a *TCPAddr) String() string {
|
|||
// numeric addresses on the network net, which must be "tcp",
|
||||
// "tcp4" or "tcp6". A literal IPv6 host address must be
|
||||
// enclosed in square brackets, as in "[::]:80".
|
||||
func ResolveTCPAddr(net, addr string) (*TCPAddr, os.Error) {
|
||||
func ResolveTCPAddr(net, addr string) (*TCPAddr, error) {
|
||||
ip, port, err := hostPortToIP(net, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -18,7 +18,7 @@ type TCPConn struct {
|
|||
|
||||
// CloseRead shuts down the reading side of the TCP connection.
|
||||
// Most callers should just use Close.
|
||||
func (c *TCPConn) CloseRead() os.Error {
|
||||
func (c *TCPConn) CloseRead() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func (c *TCPConn) CloseRead() os.Error {
|
|||
|
||||
// CloseWrite shuts down the writing side of the TCP connection.
|
||||
// Most callers should just use Close.
|
||||
func (c *TCPConn) CloseWrite() os.Error {
|
||||
func (c *TCPConn) CloseWrite() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func (c *TCPConn) CloseWrite() os.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.
|
||||
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.Error) {
|
||||
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err error) {
|
||||
switch net {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
default:
|
||||
|
@ -64,7 +64,7 @@ type TCPListener struct {
|
|||
// Net must be "tcp", "tcp4", or "tcp6".
|
||||
// If laddr has a port of 0, it means to listen on some available port.
|
||||
// The caller can use l.Addr() to retrieve the chosen address.
|
||||
func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err os.Error) {
|
||||
func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err error) {
|
||||
switch net {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
default:
|
||||
|
|
|
@ -39,7 +39,7 @@ func (a *TCPAddr) family() int {
|
|||
return syscall.AF_INET6
|
||||
}
|
||||
|
||||
func (a *TCPAddr) sockaddr(family int) (syscall.Sockaddr, os.Error) {
|
||||
func (a *TCPAddr) sockaddr(family int) (syscall.Sockaddr, error) {
|
||||
return ipToSockaddr(family, a.IP, a.Port)
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (c *TCPConn) ok() bool { return c != nil && c.fd != nil }
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *TCPConn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *TCPConn) Read(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func (c *TCPConn) Read(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// ReadFrom implements the io.ReaderFrom ReadFrom method.
|
||||
func (c *TCPConn) ReadFrom(r io.Reader) (int64, os.Error) {
|
||||
func (c *TCPConn) ReadFrom(r io.Reader) (int64, error) {
|
||||
if n, err, handled := sendFile(c.fd, r); handled {
|
||||
return n, err
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func (c *TCPConn) ReadFrom(r io.Reader) (int64, os.Error) {
|
|||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *TCPConn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *TCPConn) Write(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func (c *TCPConn) Write(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Close closes the TCP connection.
|
||||
func (c *TCPConn) Close() os.Error {
|
||||
func (c *TCPConn) Close() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ func (c *TCPConn) Close() os.Error {
|
|||
|
||||
// CloseRead shuts down the reading side of the TCP connection.
|
||||
// Most callers should just use Close.
|
||||
func (c *TCPConn) CloseRead() os.Error {
|
||||
func (c *TCPConn) CloseRead() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ func (c *TCPConn) CloseRead() os.Error {
|
|||
|
||||
// CloseWrite shuts down the writing side of the TCP connection.
|
||||
// Most callers should just use Close.
|
||||
func (c *TCPConn) CloseWrite() os.Error {
|
||||
func (c *TCPConn) CloseWrite() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func (c *TCPConn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *TCPConn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *TCPConn) SetTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ func (c *TCPConn) SetTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *TCPConn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *TCPConn) SetReadTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func (c *TCPConn) SetReadTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *TCPConn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *TCPConn) SetWriteTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func (c *TCPConn) SetWriteTimeout(nsec int64) os.Error {
|
|||
|
||||
// SetReadBuffer sets the size of the operating system's
|
||||
// receive buffer associated with the connection.
|
||||
func (c *TCPConn) SetReadBuffer(bytes int) os.Error {
|
||||
func (c *TCPConn) SetReadBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ func (c *TCPConn) SetReadBuffer(bytes int) os.Error {
|
|||
|
||||
// SetWriteBuffer sets the size of the operating system's
|
||||
// transmit buffer associated with the connection.
|
||||
func (c *TCPConn) SetWriteBuffer(bytes int) os.Error {
|
||||
func (c *TCPConn) SetWriteBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ func (c *TCPConn) SetWriteBuffer(bytes int) os.Error {
|
|||
//
|
||||
// If sec > 0, Close blocks for at most sec seconds waiting for
|
||||
// data to be sent and acknowledged.
|
||||
func (c *TCPConn) SetLinger(sec int) os.Error {
|
||||
func (c *TCPConn) SetLinger(sec int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ func (c *TCPConn) SetLinger(sec int) os.Error {
|
|||
|
||||
// SetKeepAlive sets whether the operating system should send
|
||||
// keepalive messages on the connection.
|
||||
func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error {
|
||||
func (c *TCPConn) SetKeepAlive(keepalive bool) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error {
|
|||
// 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) os.Error {
|
||||
func (c *TCPConn) SetNoDelay(noDelay bool) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -217,12 +217,12 @@ func (c *TCPConn) SetNoDelay(noDelay bool) os.Error {
|
|||
// 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 c does not affect f, and closing f does not affect c.
|
||||
func (c *TCPConn) File() (f *os.File, err os.Error) { return c.fd.dup() }
|
||||
func (c *TCPConn) File() (f *os.File, err error) { return c.fd.dup() }
|
||||
|
||||
// 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.
|
||||
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.Error) {
|
||||
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err error) {
|
||||
if raddr == nil {
|
||||
return nil, &OpError{"dial", "tcp", nil, errMissingAddress}
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ type TCPListener struct {
|
|||
// Net must be "tcp", "tcp4", or "tcp6".
|
||||
// If laddr has a port of 0, it means to listen on some available port.
|
||||
// The caller can use l.Addr() to retrieve the chosen address.
|
||||
func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err os.Error) {
|
||||
func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err error) {
|
||||
fd, err := internetSocket(net, laddr.toAddr(), nil, syscall.SOCK_STREAM, 0, "listen", sockaddrToTCP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -261,7 +261,7 @@ func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err os.Error) {
|
|||
|
||||
// AcceptTCP accepts the next incoming call and returns the new connection
|
||||
// and the remote address.
|
||||
func (l *TCPListener) AcceptTCP() (c *TCPConn, err os.Error) {
|
||||
func (l *TCPListener) AcceptTCP() (c *TCPConn, err error) {
|
||||
if l == nil || l.fd == nil || l.fd.sysfd < 0 {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ func (l *TCPListener) AcceptTCP() (c *TCPConn, err os.Error) {
|
|||
|
||||
// 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 os.Error) {
|
||||
func (l *TCPListener) Accept() (c Conn, err error) {
|
||||
c1, err := l.AcceptTCP()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -284,7 +284,7 @@ func (l *TCPListener) Accept() (c Conn, err os.Error) {
|
|||
|
||||
// Close stops listening on the TCP address.
|
||||
// Already Accepted connections are not closed.
|
||||
func (l *TCPListener) Close() os.Error {
|
||||
func (l *TCPListener) Close() error {
|
||||
if l == nil || l.fd == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ func (l *TCPListener) Close() os.Error {
|
|||
func (l *TCPListener) Addr() Addr { return l.fd.laddr }
|
||||
|
||||
// SetTimeout sets the deadline associated with the listener
|
||||
func (l *TCPListener) SetTimeout(nsec int64) os.Error {
|
||||
func (l *TCPListener) SetTimeout(nsec int64) error {
|
||||
if l == nil || l.fd == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -305,4 +305,4 @@ func (l *TCPListener) SetTimeout(nsec int64) os.Error {
|
|||
// 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 c does not affect f, and closing f does not affect c.
|
||||
func (l *TCPListener) File() (f *os.File, err os.Error) { return l.fd.dup() }
|
||||
func (l *TCPListener) File() (f *os.File, err error) { return l.fd.dup() }
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -32,13 +31,13 @@ func NewReader(r *bufio.Reader) *Reader {
|
|||
|
||||
// ReadLine reads a single line from r,
|
||||
// eliding the final \n or \r\n from the returned string.
|
||||
func (r *Reader) ReadLine() (string, os.Error) {
|
||||
func (r *Reader) ReadLine() (string, error) {
|
||||
line, err := r.readLineSlice()
|
||||
return string(line), err
|
||||
}
|
||||
|
||||
// ReadLineBytes is like ReadLine but returns a []byte instead of a string.
|
||||
func (r *Reader) ReadLineBytes() ([]byte, os.Error) {
|
||||
func (r *Reader) ReadLineBytes() ([]byte, error) {
|
||||
line, err := r.readLineSlice()
|
||||
if line != nil {
|
||||
buf := make([]byte, len(line))
|
||||
|
@ -48,7 +47,7 @@ func (r *Reader) ReadLineBytes() ([]byte, os.Error) {
|
|||
return line, err
|
||||
}
|
||||
|
||||
func (r *Reader) readLineSlice() ([]byte, os.Error) {
|
||||
func (r *Reader) readLineSlice() ([]byte, error) {
|
||||
r.closeDot()
|
||||
var line []byte
|
||||
for {
|
||||
|
@ -87,7 +86,7 @@ func (r *Reader) readLineSlice() ([]byte, os.Error) {
|
|||
//
|
||||
// A line consisting of only white space is never continued.
|
||||
//
|
||||
func (r *Reader) ReadContinuedLine() (string, os.Error) {
|
||||
func (r *Reader) ReadContinuedLine() (string, error) {
|
||||
line, err := r.readContinuedLineSlice()
|
||||
return string(line), err
|
||||
}
|
||||
|
@ -108,7 +107,7 @@ func trim(s []byte) []byte {
|
|||
|
||||
// ReadContinuedLineBytes is like ReadContinuedLine but
|
||||
// returns a []byte instead of a string.
|
||||
func (r *Reader) ReadContinuedLineBytes() ([]byte, os.Error) {
|
||||
func (r *Reader) ReadContinuedLineBytes() ([]byte, error) {
|
||||
line, err := r.readContinuedLineSlice()
|
||||
if line != nil {
|
||||
buf := make([]byte, len(line))
|
||||
|
@ -118,7 +117,7 @@ func (r *Reader) ReadContinuedLineBytes() ([]byte, os.Error) {
|
|||
return line, err
|
||||
}
|
||||
|
||||
func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) {
|
||||
func (r *Reader) readContinuedLineSlice() ([]byte, error) {
|
||||
// Read the first line.
|
||||
line, err := r.readLineSlice()
|
||||
if err != nil {
|
||||
|
@ -192,7 +191,7 @@ func (r *Reader) readContinuedLineSlice() ([]byte, os.Error) {
|
|||
return line, err
|
||||
}
|
||||
|
||||
func (r *Reader) readCodeLine(expectCode int) (code int, continued bool, message string, err os.Error) {
|
||||
func (r *Reader) readCodeLine(expectCode int) (code int, continued bool, message string, err error) {
|
||||
line, err := r.ReadLine()
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -200,7 +199,7 @@ func (r *Reader) readCodeLine(expectCode int) (code int, continued bool, message
|
|||
return parseCodeLine(line, expectCode)
|
||||
}
|
||||
|
||||
func parseCodeLine(line string, expectCode int) (code int, continued bool, message string, err os.Error) {
|
||||
func parseCodeLine(line string, expectCode int) (code int, continued bool, message string, err error) {
|
||||
if len(line) < 4 || line[3] != ' ' && line[3] != '-' {
|
||||
err = ProtocolError("short response: " + line)
|
||||
return
|
||||
|
@ -235,7 +234,7 @@ func parseCodeLine(line string, expectCode int) (code int, continued bool, messa
|
|||
//
|
||||
// An expectCode <= 0 disables the check of the status code.
|
||||
//
|
||||
func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err os.Error) {
|
||||
func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err error) {
|
||||
code, continued, message, err := r.readCodeLine(expectCode)
|
||||
if err == nil && continued {
|
||||
err = ProtocolError("unexpected multi-line response: " + message)
|
||||
|
@ -265,7 +264,7 @@ func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err os.
|
|||
//
|
||||
// An expectCode <= 0 disables the check of the status code.
|
||||
//
|
||||
func (r *Reader) ReadResponse(expectCode int) (code int, message string, err os.Error) {
|
||||
func (r *Reader) ReadResponse(expectCode int) (code int, message string, err error) {
|
||||
code, continued, message, err := r.readCodeLine(expectCode)
|
||||
for err == nil && continued {
|
||||
line, err := r.ReadLine()
|
||||
|
@ -314,7 +313,7 @@ type dotReader struct {
|
|||
}
|
||||
|
||||
// Read satisfies reads by decoding dot-encoded data read from d.r.
|
||||
func (d *dotReader) Read(b []byte) (n int, err os.Error) {
|
||||
func (d *dotReader) Read(b []byte) (n int, err error) {
|
||||
// Run data through a simple state machine to
|
||||
// elide leading dots, rewrite trailing \r\n into \n,
|
||||
// and detect ending .\r\n line.
|
||||
|
@ -331,7 +330,7 @@ func (d *dotReader) Read(b []byte) (n int, err os.Error) {
|
|||
var c byte
|
||||
c, err = br.ReadByte()
|
||||
if err != nil {
|
||||
if err == os.EOF {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
break
|
||||
|
@ -393,7 +392,7 @@ func (d *dotReader) Read(b []byte) (n int, err os.Error) {
|
|||
n++
|
||||
}
|
||||
if err == nil && d.state == stateEOF {
|
||||
err = os.EOF
|
||||
err = io.EOF
|
||||
}
|
||||
if err != nil && d.r.dot == d {
|
||||
d.r.dot = nil
|
||||
|
@ -418,7 +417,7 @@ func (r *Reader) closeDot() {
|
|||
// ReadDotBytes reads a dot-encoding and returns the decoded data.
|
||||
//
|
||||
// See the documentation for the DotReader method for details about dot-encoding.
|
||||
func (r *Reader) ReadDotBytes() ([]byte, os.Error) {
|
||||
func (r *Reader) ReadDotBytes() ([]byte, error) {
|
||||
return ioutil.ReadAll(r.DotReader())
|
||||
}
|
||||
|
||||
|
@ -426,17 +425,17 @@ func (r *Reader) ReadDotBytes() ([]byte, os.Error) {
|
|||
// containing the decoded lines, with the final \r\n or \n elided from each.
|
||||
//
|
||||
// See the documentation for the DotReader method for details about dot-encoding.
|
||||
func (r *Reader) ReadDotLines() ([]string, os.Error) {
|
||||
func (r *Reader) ReadDotLines() ([]string, error) {
|
||||
// We could use ReadDotBytes and then Split it,
|
||||
// but reading a line at a time avoids needing a
|
||||
// large contiguous block of memory and is simpler.
|
||||
var v []string
|
||||
var err os.Error
|
||||
var err error
|
||||
for {
|
||||
var line string
|
||||
line, err = r.ReadLine()
|
||||
if err != nil {
|
||||
if err == os.EOF {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
break
|
||||
|
@ -474,7 +473,7 @@ func (r *Reader) ReadDotLines() ([]string, os.Error) {
|
|||
// "Long-Key": {"Even Longer Value"},
|
||||
// }
|
||||
//
|
||||
func (r *Reader) ReadMIMEHeader() (MIMEHeader, os.Error) {
|
||||
func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) {
|
||||
m := make(MIMEHeader)
|
||||
for {
|
||||
kv, err := r.readContinuedLineSlice()
|
||||
|
|
|
@ -7,7 +7,6 @@ package textproto
|
|||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -49,7 +48,7 @@ func TestReadLine(t *testing.T) {
|
|||
t.Fatalf("Line 2: %s, %v", s, err)
|
||||
}
|
||||
s, err = r.ReadLine()
|
||||
if s != "" || err != os.EOF {
|
||||
if s != "" || err != io.EOF {
|
||||
t.Fatalf("EOF: %s, %v", s, err)
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ func TestReadContinuedLine(t *testing.T) {
|
|||
t.Fatalf("Line 3: %s, %v", s, err)
|
||||
}
|
||||
s, err = r.ReadContinuedLine()
|
||||
if s != "" || err != os.EOF {
|
||||
if s != "" || err != io.EOF {
|
||||
t.Fatalf("EOF: %s, %v", s, err)
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +91,7 @@ func TestReadCodeLine(t *testing.T) {
|
|||
t.Fatalf("Line 3: wrong error %v\n", err)
|
||||
}
|
||||
code, msg, err = r.ReadCodeLine(1)
|
||||
if code != 0 || msg != "" || err != os.EOF {
|
||||
if code != 0 || msg != "" || err != io.EOF {
|
||||
t.Fatalf("EOF: %d, %s, %v", code, msg, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
// An Error represents a numeric error response from a server.
|
||||
|
@ -36,7 +35,7 @@ type Error struct {
|
|||
Msg string
|
||||
}
|
||||
|
||||
func (e *Error) String() string {
|
||||
func (e *Error) Error() string {
|
||||
return fmt.Sprintf("%03d %s", e.Code, e.Msg)
|
||||
}
|
||||
|
||||
|
@ -44,7 +43,7 @@ func (e *Error) String() string {
|
|||
// as an invalid response or a hung-up connection.
|
||||
type ProtocolError string
|
||||
|
||||
func (p ProtocolError) String() string {
|
||||
func (p ProtocolError) Error() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
|
@ -70,13 +69,13 @@ func NewConn(conn io.ReadWriteCloser) *Conn {
|
|||
}
|
||||
|
||||
// Close closes the connection.
|
||||
func (c *Conn) Close() os.Error {
|
||||
func (c *Conn) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
// Dial connects to the given address on the given network using net.Dial
|
||||
// and then returns a new Conn for the connection.
|
||||
func Dial(network, addr string) (*Conn, os.Error) {
|
||||
func Dial(network, addr string) (*Conn, error) {
|
||||
c, err := net.Dial(network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -109,7 +108,7 @@ func Dial(network, addr string) (*Conn, os.Error) {
|
|||
// }
|
||||
// return c.ReadCodeLine(250)
|
||||
//
|
||||
func (c *Conn) Cmd(format string, args ...interface{}) (id uint, err os.Error) {
|
||||
func (c *Conn) Cmd(format string, args ...interface{}) (id uint, err error) {
|
||||
id = c.Next()
|
||||
c.StartRequest(id)
|
||||
err = c.PrintfLine(format, args...)
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// A Writer implements convenience methods for writing
|
||||
|
@ -27,7 +26,7 @@ var crnl = []byte{'\r', '\n'}
|
|||
var dotcrnl = []byte{'.', '\r', '\n'}
|
||||
|
||||
// PrintfLine writes the formatted output followed by \r\n.
|
||||
func (w *Writer) PrintfLine(format string, args ...interface{}) os.Error {
|
||||
func (w *Writer) PrintfLine(format string, args ...interface{}) error {
|
||||
w.closeDot()
|
||||
fmt.Fprintf(w.W, format, args...)
|
||||
w.W.Write(crnl)
|
||||
|
@ -64,7 +63,7 @@ const (
|
|||
wstateData // writing data in middle of line
|
||||
)
|
||||
|
||||
func (d *dotWriter) Write(b []byte) (n int, err os.Error) {
|
||||
func (d *dotWriter) Write(b []byte) (n int, err error) {
|
||||
bw := d.w.W
|
||||
for n < len(b) {
|
||||
c := b[n]
|
||||
|
@ -100,7 +99,7 @@ func (d *dotWriter) Write(b []byte) (n int, err os.Error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (d *dotWriter) Close() os.Error {
|
||||
func (d *dotWriter) Close() error {
|
||||
if d.w.dot == d {
|
||||
d.w.dot = nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -22,7 +21,7 @@ func testTimeout(t *testing.T, network, addr string, readFrom bool) {
|
|||
fd.SetReadTimeout(1e8) // 100ms
|
||||
var b [100]byte
|
||||
var n int
|
||||
var err1 os.Error
|
||||
var err1 error
|
||||
if readFrom {
|
||||
n, _, err1 = fd.(PacketConn).ReadFrom(b[0:])
|
||||
} else {
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// UDPAddr represents the address of a UDP end point.
|
||||
type UDPAddr struct {
|
||||
IP IP
|
||||
|
@ -31,7 +27,7 @@ func (a *UDPAddr) String() string {
|
|||
// numeric addresses on the network net, which must be "udp",
|
||||
// "udp4" or "udp6". A literal IPv6 host address must be
|
||||
// enclosed in square brackets, as in "[::]:80".
|
||||
func ResolveUDPAddr(net, addr string) (*UDPAddr, os.Error) {
|
||||
func ResolveUDPAddr(net, addr string) (*UDPAddr, error) {
|
||||
ip, port, err := hostPortToIP(net, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -24,7 +25,7 @@ type UDPConn struct {
|
|||
//
|
||||
// ReadFromUDP can be made to time out and return an error with Timeout() == true
|
||||
// after a fixed time limit; see SetTimeout and SetReadTimeout.
|
||||
func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
|
||||
func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -40,7 +41,7 @@ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
|
|||
return
|
||||
}
|
||||
if m < udpHeaderSize {
|
||||
return 0, nil, os.NewError("short read reading UDP header")
|
||||
return 0, nil, errors.New("short read reading UDP header")
|
||||
}
|
||||
buf = buf[:m]
|
||||
|
||||
|
@ -50,7 +51,7 @@ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
|
|||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
||||
func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -63,7 +64,7 @@ func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
|||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetWriteTimeout.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err os.Error) {
|
||||
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -87,7 +88,7 @@ func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
||||
func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -101,7 +102,7 @@ func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
|||
// 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
|
||||
// as the local address for the connection.
|
||||
func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err os.Error) {
|
||||
func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err error) {
|
||||
switch net {
|
||||
case "udp", "udp4", "udp6":
|
||||
default:
|
||||
|
@ -149,7 +150,7 @@ func unmarshalUDPHeader(b []byte) (*udpHeader, []byte) {
|
|||
// local address laddr. The returned connection c's ReadFrom
|
||||
// and WriteTo methods can be used to receive and send UDP
|
||||
// packets with per-packet addressing.
|
||||
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error) {
|
||||
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err error) {
|
||||
switch net {
|
||||
case "udp", "udp4", "udp6":
|
||||
default:
|
||||
|
@ -172,7 +173,7 @@ func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error) {
|
|||
// JoinGroup joins the IP multicast group named by addr on ifi,
|
||||
// which specifies the interface to join. JoinGroup uses the
|
||||
// default multicast interface if ifi is nil.
|
||||
func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) os.Error {
|
||||
func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) os.Error {
|
|||
}
|
||||
|
||||
// LeaveGroup exits the IP multicast group named by addr on ifi.
|
||||
func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) os.Error {
|
||||
func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (a *UDPAddr) family() int {
|
|||
return syscall.AF_INET6
|
||||
}
|
||||
|
||||
func (a *UDPAddr) sockaddr(family int) (syscall.Sockaddr, os.Error) {
|
||||
func (a *UDPAddr) sockaddr(family int) (syscall.Sockaddr, error) {
|
||||
return ipToSockaddr(family, a.IP, a.Port)
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ func (c *UDPConn) ok() bool { return c != nil && c.fd != nil }
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *UDPConn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *UDPConn) Read(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (c *UDPConn) Read(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *UDPConn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *UDPConn) Write(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (c *UDPConn) Write(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Close closes the UDP connection.
|
||||
func (c *UDPConn) Close() os.Error {
|
||||
func (c *UDPConn) Close() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (c *UDPConn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *UDPConn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *UDPConn) SetTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func (c *UDPConn) SetTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *UDPConn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *UDPConn) SetReadTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func (c *UDPConn) SetReadTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *UDPConn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *UDPConn) SetWriteTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ func (c *UDPConn) SetWriteTimeout(nsec int64) os.Error {
|
|||
|
||||
// SetReadBuffer sets the size of the operating system's
|
||||
// receive buffer associated with the connection.
|
||||
func (c *UDPConn) SetReadBuffer(bytes int) os.Error {
|
||||
func (c *UDPConn) SetReadBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ func (c *UDPConn) SetReadBuffer(bytes int) os.Error {
|
|||
|
||||
// SetWriteBuffer sets the size of the operating system's
|
||||
// transmit buffer associated with the connection.
|
||||
func (c *UDPConn) SetWriteBuffer(bytes int) os.Error {
|
||||
func (c *UDPConn) SetWriteBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ func (c *UDPConn) SetWriteBuffer(bytes int) os.Error {
|
|||
//
|
||||
// ReadFromUDP can be made to time out and return an error with Timeout() == true
|
||||
// after a fixed time limit; see SetTimeout and SetReadTimeout.
|
||||
func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
|
||||
func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
|
|||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
||||
func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -178,19 +178,19 @@ func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
|||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetWriteTimeout.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err os.Error) {
|
||||
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
sa, err1 := addr.sockaddr(c.fd.family)
|
||||
if err1 != nil {
|
||||
return 0, &OpError{Op: "write", Net: "udp", Addr: addr, Error: err1}
|
||||
return 0, &OpError{Op: "write", Net: "udp", Addr: addr, Err: err1}
|
||||
}
|
||||
return c.fd.WriteTo(b, sa)
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
||||
func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
|||
// 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
|
||||
// as the local address for the connection.
|
||||
func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err os.Error) {
|
||||
func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err error) {
|
||||
switch net {
|
||||
case "udp", "udp4", "udp6":
|
||||
default:
|
||||
|
@ -224,7 +224,7 @@ func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err os.Error) {
|
|||
// local address laddr. The returned connection c's ReadFrom
|
||||
// and WriteTo methods can be used to receive and send UDP
|
||||
// packets with per-packet addressing.
|
||||
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error) {
|
||||
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err error) {
|
||||
switch net {
|
||||
case "udp", "udp4", "udp6":
|
||||
default:
|
||||
|
@ -241,7 +241,7 @@ func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error) {
|
|||
}
|
||||
|
||||
// BindToDevice binds a UDPConn to a network interface.
|
||||
func (c *UDPConn) BindToDevice(device string) os.Error {
|
||||
func (c *UDPConn) BindToDevice(device string) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -253,12 +253,12 @@ func (c *UDPConn) BindToDevice(device string) os.Error {
|
|||
// 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 c does not affect f, and closing f does not affect c.
|
||||
func (c *UDPConn) File() (f *os.File, err os.Error) { return c.fd.dup() }
|
||||
func (c *UDPConn) File() (f *os.File, err error) { return c.fd.dup() }
|
||||
|
||||
// JoinGroup joins the IP multicast group named by addr on ifi,
|
||||
// which specifies the interface to join. JoinGroup uses the
|
||||
// default multicast interface if ifi is nil.
|
||||
func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) os.Error {
|
||||
func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func (c *UDPConn) JoinGroup(ifi *Interface, addr IP) os.Error {
|
|||
}
|
||||
|
||||
// LeaveGroup exits the IP multicast group named by addr on ifi.
|
||||
func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) os.Error {
|
||||
func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) os.Error {
|
|||
return leaveIPv6GroupUDP(c, ifi, addr)
|
||||
}
|
||||
|
||||
func joinIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
||||
func joinIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
|
||||
if err := setIPv4InterfaceToJoin(mreq, ifi); err != nil {
|
||||
return &OpError{"joinipv4group", "udp", &IPAddr{ip}, err}
|
||||
|
@ -292,7 +292,7 @@ func joinIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func leaveIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
||||
func leaveIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
|
||||
if err := setIPv4InterfaceToJoin(mreq, ifi); err != nil {
|
||||
return &OpError{"leaveipv4group", "udp", &IPAddr{ip}, err}
|
||||
|
@ -303,7 +303,7 @@ func leaveIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func setIPv4InterfaceToJoin(mreq *syscall.IPMreq, ifi *Interface) os.Error {
|
||||
func setIPv4InterfaceToJoin(mreq *syscall.IPMreq, ifi *Interface) error {
|
||||
if ifi == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ func setIPv4InterfaceToJoin(mreq *syscall.IPMreq, ifi *Interface) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func joinIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
||||
func joinIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
mreq := &syscall.IPv6Mreq{}
|
||||
copy(mreq.Multiaddr[:], ip)
|
||||
if ifi != nil {
|
||||
|
@ -335,7 +335,7 @@ func joinIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func leaveIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) os.Error {
|
||||
func leaveIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
mreq := &syscall.IPv6Mreq{}
|
||||
copy(mreq.Multiaddr[:], ip)
|
||||
if ifi != nil {
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// UnixAddr represents the address of a Unix domain socket end point.
|
||||
type UnixAddr struct {
|
||||
Name string
|
||||
|
@ -38,7 +34,7 @@ func (a *UnixAddr) toAddr() Addr {
|
|||
// ResolveUnixAddr parses addr as a Unix domain socket address.
|
||||
// The string net gives the network name, "unix", "unixgram" or
|
||||
// "unixpacket".
|
||||
func ResolveUnixAddr(net, addr string) (*UnixAddr, os.Error) {
|
||||
func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
|
||||
switch net {
|
||||
case "unix":
|
||||
case "unixpacket":
|
||||
|
|
|
@ -17,17 +17,17 @@ type UnixConn bool
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *UnixConn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *UnixConn) Read(b []byte) (n int, err error) {
|
||||
return 0, os.EPLAN9
|
||||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *UnixConn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *UnixConn) Write(b []byte) (n int, err error) {
|
||||
return 0, os.EPLAN9
|
||||
}
|
||||
|
||||
// Close closes the Unix domain connection.
|
||||
func (c *UnixConn) Close() os.Error {
|
||||
func (c *UnixConn) Close() error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
|
@ -45,28 +45,28 @@ func (c *UnixConn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *UnixConn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *UnixConn) SetTimeout(nsec int64) error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *UnixConn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *UnixConn) SetReadTimeout(nsec int64) error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *UnixConn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *UnixConn) SetWriteTimeout(nsec int64) error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
||||
func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
err = os.EPLAN9
|
||||
return
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
||||
func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
err = os.EPLAN9
|
||||
return
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
|||
// DialUnix connects to the remote address raddr on the network net,
|
||||
// which must be "unix" or "unixgram". If laddr is not nil, it is used
|
||||
// as the local address for the connection.
|
||||
func DialUnix(net string, laddr, raddr *UnixAddr) (c *UnixConn, err os.Error) {
|
||||
func DialUnix(net string, laddr, raddr *UnixAddr) (c *UnixConn, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
||||
|
@ -85,19 +85,19 @@ type UnixListener bool
|
|||
|
||||
// ListenUnix announces on the Unix domain socket laddr and returns a Unix listener.
|
||||
// Net must be "unix" (stream sockets).
|
||||
func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error) {
|
||||
func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
||||
// Accept implements the Accept method in the Listener interface;
|
||||
// it waits for the next call and returns a generic Conn.
|
||||
func (l *UnixListener) Accept() (c Conn, err os.Error) {
|
||||
func (l *UnixListener) Accept() (c Conn, err error) {
|
||||
return nil, os.EPLAN9
|
||||
}
|
||||
|
||||
// Close stops listening on the Unix address.
|
||||
// Already accepted connections are not closed.
|
||||
func (l *UnixListener) Close() os.Error {
|
||||
func (l *UnixListener) Close() error {
|
||||
return os.EPLAN9
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func unixSocket(net string, laddr, raddr *UnixAddr, mode string) (fd *netFD, err os.Error) {
|
||||
func unixSocket(net string, laddr, raddr *UnixAddr, mode string) (fd *netFD, err error) {
|
||||
var proto int
|
||||
switch net {
|
||||
default:
|
||||
|
@ -38,7 +38,7 @@ func unixSocket(net string, laddr, raddr *UnixAddr, mode string) (fd *netFD, err
|
|||
if raddr != nil {
|
||||
ra = &syscall.SockaddrUnix{Name: raddr.Name}
|
||||
} else if proto != syscall.SOCK_DGRAM || laddr == nil {
|
||||
return nil, &OpError{Op: mode, Net: net, Error: errMissingAddress}
|
||||
return nil, &OpError{Op: mode, Net: net, Err: errMissingAddress}
|
||||
}
|
||||
|
||||
case "listen":
|
||||
|
@ -47,7 +47,7 @@ func unixSocket(net string, laddr, raddr *UnixAddr, mode string) (fd *netFD, err
|
|||
}
|
||||
la = &syscall.SockaddrUnix{Name: laddr.Name}
|
||||
if raddr != nil {
|
||||
return nil, &OpError{Op: mode, Net: net, Addr: raddr, Error: &AddrError{Error: "unexpected remote address", Addr: raddr.String()}}
|
||||
return nil, &OpError{Op: mode, Net: net, Addr: raddr, Err: &AddrError{Err: "unexpected remote address", Addr: raddr.String()}}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ Error:
|
|||
if mode == "listen" {
|
||||
addr = laddr
|
||||
}
|
||||
return nil, &OpError{Op: mode, Net: net, Addr: addr, Error: oserr}
|
||||
return nil, &OpError{Op: mode, Net: net, Addr: addr, Err: oserr}
|
||||
}
|
||||
|
||||
func sockaddrToUnix(sa syscall.Sockaddr) Addr {
|
||||
|
@ -120,7 +120,7 @@ func (c *UnixConn) ok() bool { return c != nil && c.fd != nil }
|
|||
// Implementation of the Conn interface - see Conn for documentation.
|
||||
|
||||
// Read implements the net.Conn Read method.
|
||||
func (c *UnixConn) Read(b []byte) (n int, err os.Error) {
|
||||
func (c *UnixConn) Read(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func (c *UnixConn) Read(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Write implements the net.Conn Write method.
|
||||
func (c *UnixConn) Write(b []byte) (n int, err os.Error) {
|
||||
func (c *UnixConn) Write(b []byte) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ func (c *UnixConn) Write(b []byte) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// Close closes the Unix domain connection.
|
||||
func (c *UnixConn) Close() os.Error {
|
||||
func (c *UnixConn) Close() error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ func (c *UnixConn) RemoteAddr() Addr {
|
|||
}
|
||||
|
||||
// SetTimeout implements the net.Conn SetTimeout method.
|
||||
func (c *UnixConn) SetTimeout(nsec int64) os.Error {
|
||||
func (c *UnixConn) SetTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func (c *UnixConn) SetTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetReadTimeout implements the net.Conn SetReadTimeout method.
|
||||
func (c *UnixConn) SetReadTimeout(nsec int64) os.Error {
|
||||
func (c *UnixConn) SetReadTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func (c *UnixConn) SetReadTimeout(nsec int64) os.Error {
|
|||
}
|
||||
|
||||
// SetWriteTimeout implements the net.Conn SetWriteTimeout method.
|
||||
func (c *UnixConn) SetWriteTimeout(nsec int64) os.Error {
|
||||
func (c *UnixConn) SetWriteTimeout(nsec int64) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ func (c *UnixConn) SetWriteTimeout(nsec int64) os.Error {
|
|||
|
||||
// SetReadBuffer sets the size of the operating system's
|
||||
// receive buffer associated with the connection.
|
||||
func (c *UnixConn) SetReadBuffer(bytes int) os.Error {
|
||||
func (c *UnixConn) SetReadBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ func (c *UnixConn) SetReadBuffer(bytes int) os.Error {
|
|||
|
||||
// SetWriteBuffer sets the size of the operating system's
|
||||
// transmit buffer associated with the connection.
|
||||
func (c *UnixConn) SetWriteBuffer(bytes int) os.Error {
|
||||
func (c *UnixConn) SetWriteBuffer(bytes int) error {
|
||||
if !c.ok() {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func (c *UnixConn) SetWriteBuffer(bytes int) os.Error {
|
|||
// ReadFromUnix can be made to time out and return
|
||||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetReadTimeout.
|
||||
func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err os.Error) {
|
||||
func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err os.Error)
|
|||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
||||
func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error) {
|
|||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetTimeout and SetWriteTimeout.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
func (c *UnixConn) WriteToUnix(b []byte, addr *UnixAddr) (n int, err os.Error) {
|
||||
func (c *UnixConn) WriteToUnix(b []byte, addr *UnixAddr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ func (c *UnixConn) WriteToUnix(b []byte, addr *UnixAddr) (n int, err os.Error) {
|
|||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
||||
func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err os.Error) {
|
|||
return c.WriteToUnix(b, a)
|
||||
}
|
||||
|
||||
func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err os.Error) {
|
||||
func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, 0, 0, nil, os.EINVAL
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAdd
|
|||
return
|
||||
}
|
||||
|
||||
func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err os.Error) {
|
||||
func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, 0, os.EINVAL
|
||||
}
|
||||
|
@ -292,12 +292,12 @@ func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err
|
|||
// 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 c does not affect f, and closing f does not affect c.
|
||||
func (c *UnixConn) File() (f *os.File, err os.Error) { return c.fd.dup() }
|
||||
func (c *UnixConn) File() (f *os.File, err error) { return c.fd.dup() }
|
||||
|
||||
// DialUnix connects to the remote address raddr on the network net,
|
||||
// which must be "unix" or "unixgram". If laddr is not nil, it is used
|
||||
// as the local address for the connection.
|
||||
func DialUnix(net string, laddr, raddr *UnixAddr) (c *UnixConn, err os.Error) {
|
||||
func DialUnix(net string, laddr, raddr *UnixAddr) (c *UnixConn, err error) {
|
||||
fd, e := unixSocket(net, laddr, raddr, "dial")
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
@ -315,7 +315,7 @@ type UnixListener struct {
|
|||
|
||||
// ListenUnix announces on the Unix domain socket laddr and returns a Unix listener.
|
||||
// Net must be "unix" (stream sockets).
|
||||
func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error) {
|
||||
func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err error) {
|
||||
if net != "unix" && net != "unixgram" && net != "unixpacket" {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
|
@ -329,14 +329,14 @@ func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error) {
|
|||
e1 := syscall.Listen(fd.sysfd, 8) // listenBacklog());
|
||||
if e1 != 0 {
|
||||
closesocket(fd.sysfd)
|
||||
return nil, &OpError{Op: "listen", Net: "unix", Addr: laddr, Error: os.Errno(e1)}
|
||||
return nil, &OpError{Op: "listen", Net: "unix", Addr: laddr, Err: os.Errno(e1)}
|
||||
}
|
||||
return &UnixListener{fd, laddr.Name}, nil
|
||||
}
|
||||
|
||||
// AcceptUnix accepts the next incoming call and returns the new connection
|
||||
// and the remote address.
|
||||
func (l *UnixListener) AcceptUnix() (c *UnixConn, err os.Error) {
|
||||
func (l *UnixListener) AcceptUnix() (c *UnixConn, err error) {
|
||||
if l == nil || l.fd == nil {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ func (l *UnixListener) AcceptUnix() (c *UnixConn, err os.Error) {
|
|||
|
||||
// Accept implements the Accept method in the Listener interface;
|
||||
// it waits for the next call and returns a generic Conn.
|
||||
func (l *UnixListener) Accept() (c Conn, err os.Error) {
|
||||
func (l *UnixListener) Accept() (c Conn, err error) {
|
||||
c1, err := l.AcceptUnix()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -360,7 +360,7 @@ func (l *UnixListener) Accept() (c Conn, err os.Error) {
|
|||
|
||||
// Close stops listening on the Unix address.
|
||||
// Already accepted connections are not closed.
|
||||
func (l *UnixListener) Close() os.Error {
|
||||
func (l *UnixListener) Close() error {
|
||||
if l == nil || l.fd == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ func (l *UnixListener) Close() os.Error {
|
|||
func (l *UnixListener) Addr() Addr { return l.fd.laddr }
|
||||
|
||||
// SetTimeout sets the deadline associated wuth the listener
|
||||
func (l *UnixListener) SetTimeout(nsec int64) (err os.Error) {
|
||||
func (l *UnixListener) SetTimeout(nsec int64) (err error) {
|
||||
if l == nil || l.fd == nil {
|
||||
return os.EINVAL
|
||||
}
|
||||
|
@ -397,13 +397,13 @@ func (l *UnixListener) SetTimeout(nsec int64) (err os.Error) {
|
|||
// 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 c does not affect f, and closing f does not affect c.
|
||||
func (l *UnixListener) File() (f *os.File, err os.Error) { return l.fd.dup() }
|
||||
func (l *UnixListener) File() (f *os.File, err error) { return l.fd.dup() }
|
||||
|
||||
// ListenUnixgram listens for incoming Unix datagram packets addressed to the
|
||||
// local address laddr. The returned connection c's ReadFrom
|
||||
// and WriteTo methods can be used to receive and send UDP
|
||||
// packets with per-packet addressing. The network net must be "unixgram".
|
||||
func ListenUnixgram(net string, laddr *UnixAddr) (c *UDPConn, err os.Error) {
|
||||
func ListenUnixgram(net string, laddr *UnixAddr) (c *UDPConn, err error) {
|
||||
switch net {
|
||||
case "unixgram":
|
||||
default:
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
package netchan
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gob"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -60,7 +60,7 @@ type request struct {
|
|||
}
|
||||
|
||||
// Sent with a header to report an error.
|
||||
type error struct {
|
||||
type error_ struct {
|
||||
Error string
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ func newEncDec(conn io.ReadWriter) *encDec {
|
|||
}
|
||||
|
||||
// Decode an item from the connection.
|
||||
func (ed *encDec) decode(value reflect.Value) os.Error {
|
||||
func (ed *encDec) decode(value reflect.Value) error {
|
||||
ed.decLock.Lock()
|
||||
err := ed.dec.DecodeValue(value)
|
||||
if err != nil {
|
||||
|
@ -112,7 +112,7 @@ func (ed *encDec) decode(value reflect.Value) os.Error {
|
|||
}
|
||||
|
||||
// Encode a header and payload onto the connection.
|
||||
func (ed *encDec) encode(hdr *header, payloadType int, payload interface{}) os.Error {
|
||||
func (ed *encDec) encode(hdr *header, payloadType int, payload interface{}) error {
|
||||
ed.encLock.Lock()
|
||||
hdr.PayloadType = payloadType
|
||||
err := ed.enc.Encode(hdr)
|
||||
|
@ -129,7 +129,7 @@ func (ed *encDec) encode(hdr *header, payloadType int, payload interface{}) os.E
|
|||
}
|
||||
|
||||
// See the comment for Exporter.Drain.
|
||||
func (cs *clientSet) drain(timeout int64) os.Error {
|
||||
func (cs *clientSet) drain(timeout int64) error {
|
||||
startTime := time.Nanoseconds()
|
||||
for {
|
||||
pending := false
|
||||
|
@ -153,7 +153,7 @@ func (cs *clientSet) drain(timeout int64) os.Error {
|
|||
break
|
||||
}
|
||||
if timeout > 0 && time.Nanoseconds()-startTime >= timeout {
|
||||
return os.NewError("timeout")
|
||||
return errors.New("timeout")
|
||||
}
|
||||
time.Sleep(100 * 1e6) // 100 milliseconds
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ func (cs *clientSet) drain(timeout int64) os.Error {
|
|||
}
|
||||
|
||||
// See the comment for Exporter.Sync.
|
||||
func (cs *clientSet) sync(timeout int64) os.Error {
|
||||
func (cs *clientSet) sync(timeout int64) error {
|
||||
startTime := time.Nanoseconds()
|
||||
// seq remembers the clients and their seqNum at point of entry.
|
||||
seq := make(map[unackedCounter]int64)
|
||||
|
@ -186,7 +186,7 @@ func (cs *clientSet) sync(timeout int64) os.Error {
|
|||
break
|
||||
}
|
||||
if timeout > 0 && time.Nanoseconds()-startTime >= timeout {
|
||||
return os.NewError("timeout")
|
||||
return errors.New("timeout")
|
||||
}
|
||||
time.Sleep(100 * 1e6) // 100 milliseconds
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ package netchan
|
|||
// BUG: can't use range clause to receive when using ImportNValues to limit the count.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
@ -68,7 +68,7 @@ func newClient(exp *Exporter, conn io.ReadWriter) *expClient {
|
|||
}
|
||||
|
||||
func (client *expClient) sendError(hdr *header, err string) {
|
||||
error := &error{err}
|
||||
error := &error_{err}
|
||||
expLog("sending error to client:", error.Error)
|
||||
client.encode(hdr, payError, error) // ignore any encode error, hope client gets it
|
||||
client.mu.Lock()
|
||||
|
@ -114,11 +114,11 @@ func (client *expClient) run() {
|
|||
hdrValue := reflect.ValueOf(hdr)
|
||||
req := new(request)
|
||||
reqValue := reflect.ValueOf(req)
|
||||
error := new(error)
|
||||
error := new(error_)
|
||||
for {
|
||||
*hdr = header{}
|
||||
if err := client.decode(hdrValue); err != nil {
|
||||
if err != os.EOF {
|
||||
if err != io.EOF {
|
||||
expLog("error decoding client header:", err)
|
||||
}
|
||||
break
|
||||
|
@ -201,7 +201,7 @@ func (client *expClient) serveRecv(nch *netChan, hdr header, count int64) {
|
|||
client.seqLock.Unlock()
|
||||
if err != nil {
|
||||
expLog("error encoding client response:", err)
|
||||
client.sendError(&hdr, err.String())
|
||||
client.sendError(&hdr, err.Error())
|
||||
break
|
||||
}
|
||||
// Negative count means run forever.
|
||||
|
@ -293,7 +293,7 @@ func NewExporter() *Exporter {
|
|||
|
||||
// ListenAndServe exports the exporter's channels through the
|
||||
// given network and local address defined as in net.Listen.
|
||||
func (exp *Exporter) ListenAndServe(network, localaddr string) os.Error {
|
||||
func (exp *Exporter) ListenAndServe(network, localaddr string) error {
|
||||
listener, err := net.Listen(network, localaddr)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -324,7 +324,7 @@ func (exp *Exporter) delClient(client *expClient) {
|
|||
// waits until all the exporter's messages have been received by a client.
|
||||
// If the timeout (measured in nanoseconds) is positive and Drain takes
|
||||
// longer than that to complete, an error is returned.
|
||||
func (exp *Exporter) Drain(timeout int64) os.Error {
|
||||
func (exp *Exporter) Drain(timeout int64) error {
|
||||
// This wrapper function is here so the method's comment will appear in godoc.
|
||||
return exp.clientSet.drain(timeout)
|
||||
}
|
||||
|
@ -335,28 +335,28 @@ func (exp *Exporter) Drain(timeout int64) os.Error {
|
|||
// dispatched to any client. If the timeout (measured in nanoseconds) is
|
||||
// positive and Sync takes longer than that to complete, an error is
|
||||
// returned.
|
||||
func (exp *Exporter) Sync(timeout int64) os.Error {
|
||||
func (exp *Exporter) Sync(timeout int64) error {
|
||||
// This wrapper function is here so the method's comment will appear in godoc.
|
||||
return exp.clientSet.sync(timeout)
|
||||
}
|
||||
|
||||
func checkChan(chT interface{}, dir Dir) (reflect.Value, os.Error) {
|
||||
func checkChan(chT interface{}, dir Dir) (reflect.Value, error) {
|
||||
chanType := reflect.TypeOf(chT)
|
||||
if chanType.Kind() != reflect.Chan {
|
||||
return reflect.Value{}, os.NewError("not a channel")
|
||||
return reflect.Value{}, errors.New("not a channel")
|
||||
}
|
||||
if dir != Send && dir != Recv {
|
||||
return reflect.Value{}, os.NewError("unknown channel direction")
|
||||
return reflect.Value{}, errors.New("unknown channel direction")
|
||||
}
|
||||
switch chanType.ChanDir() {
|
||||
case reflect.BothDir:
|
||||
case reflect.SendDir:
|
||||
if dir != Recv {
|
||||
return reflect.Value{}, os.NewError("to import/export with Send, must provide <-chan")
|
||||
return reflect.Value{}, errors.New("to import/export with Send, must provide <-chan")
|
||||
}
|
||||
case reflect.RecvDir:
|
||||
if dir != Send {
|
||||
return reflect.Value{}, os.NewError("to import/export with Recv, must provide chan<-")
|
||||
return reflect.Value{}, errors.New("to import/export with Recv, must provide chan<-")
|
||||
}
|
||||
}
|
||||
return reflect.ValueOf(chT), nil
|
||||
|
@ -367,7 +367,7 @@ func checkChan(chT interface{}, dir Dir) (reflect.Value, os.Error) {
|
|||
// channel type.
|
||||
// Despite the literal signature, the effective signature is
|
||||
// Export(name string, chT chan T, dir Dir)
|
||||
func (exp *Exporter) Export(name string, chT interface{}, dir Dir) os.Error {
|
||||
func (exp *Exporter) Export(name string, chT interface{}, dir Dir) error {
|
||||
ch, err := checkChan(chT, dir)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -376,7 +376,7 @@ func (exp *Exporter) Export(name string, chT interface{}, dir Dir) os.Error {
|
|||
defer exp.mu.Unlock()
|
||||
_, present := exp.names[name]
|
||||
if present {
|
||||
return os.NewError("channel name already being exported:" + name)
|
||||
return errors.New("channel name already being exported:" + name)
|
||||
}
|
||||
exp.names[name] = &chanDir{ch, dir}
|
||||
return nil
|
||||
|
@ -384,7 +384,7 @@ func (exp *Exporter) Export(name string, chT interface{}, dir Dir) os.Error {
|
|||
|
||||
// Hangup disassociates the named channel from the Exporter and closes
|
||||
// the channel. Messages in flight for the channel may be dropped.
|
||||
func (exp *Exporter) Hangup(name string) os.Error {
|
||||
func (exp *Exporter) Hangup(name string) error {
|
||||
exp.mu.Lock()
|
||||
chDir, ok := exp.names[name]
|
||||
if ok {
|
||||
|
@ -393,7 +393,7 @@ func (exp *Exporter) Hangup(name string) os.Error {
|
|||
// TODO drop all instances of channel from client sets
|
||||
exp.mu.Unlock()
|
||||
if !ok {
|
||||
return os.NewError("netchan export: hangup: no such channel: " + name)
|
||||
return errors.New("netchan export: hangup: no such channel: " + name)
|
||||
}
|
||||
chDir.ch.Close()
|
||||
return nil
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
package netchan
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -30,7 +30,7 @@ type Importer struct {
|
|||
chanLock sync.Mutex // protects access to channel map
|
||||
names map[string]*netChan
|
||||
chans map[int]*netChan
|
||||
errors chan os.Error
|
||||
errors chan error
|
||||
maxId int
|
||||
mu sync.Mutex // protects remaining fields
|
||||
unacked int64 // number of unacknowledged sends.
|
||||
|
@ -45,14 +45,14 @@ func NewImporter(conn io.ReadWriter) *Importer {
|
|||
imp.encDec = newEncDec(conn)
|
||||
imp.chans = make(map[int]*netChan)
|
||||
imp.names = make(map[string]*netChan)
|
||||
imp.errors = make(chan os.Error, 10)
|
||||
imp.errors = make(chan error, 10)
|
||||
imp.unacked = 0
|
||||
go imp.run()
|
||||
return imp
|
||||
}
|
||||
|
||||
// Import imports a set of channels from the given network and address.
|
||||
func Import(network, remoteaddr string) (*Importer, os.Error) {
|
||||
func Import(network, remoteaddr string) (*Importer, error) {
|
||||
conn, err := net.Dial(network, remoteaddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -80,12 +80,12 @@ func (imp *Importer) run() {
|
|||
hdr := new(header)
|
||||
hdrValue := reflect.ValueOf(hdr)
|
||||
ackHdr := new(header)
|
||||
err := new(error)
|
||||
err := new(error_)
|
||||
errValue := reflect.ValueOf(err)
|
||||
for {
|
||||
*hdr = header{}
|
||||
if e := imp.decode(hdrValue); e != nil {
|
||||
if e != os.EOF {
|
||||
if e != io.EOF {
|
||||
impLog("header:", e)
|
||||
imp.shutdown()
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ func (imp *Importer) run() {
|
|||
if err.Error != "" {
|
||||
impLog("response error:", err.Error)
|
||||
select {
|
||||
case imp.errors <- os.NewError(err.Error):
|
||||
case imp.errors <- errors.New(err.Error):
|
||||
continue // errors are not acknowledged
|
||||
default:
|
||||
imp.shutdown()
|
||||
|
@ -169,13 +169,13 @@ func (imp *Importer) getChan(id int, errOk bool) *netChan {
|
|||
// can be read. Clients of the importer are not required to read the error
|
||||
// channel for correct execution. However, if too many errors occur
|
||||
// without being read from the error channel, the importer will shut down.
|
||||
func (imp *Importer) Errors() chan os.Error {
|
||||
func (imp *Importer) Errors() chan error {
|
||||
return imp.errors
|
||||
}
|
||||
|
||||
// Import imports a channel of the given type, size and specified direction.
|
||||
// It is equivalent to ImportNValues with a count of -1, meaning unbounded.
|
||||
func (imp *Importer) Import(name string, chT interface{}, dir Dir, size int) os.Error {
|
||||
func (imp *Importer) Import(name string, chT interface{}, dir Dir, size int) error {
|
||||
return imp.ImportNValues(name, chT, dir, size, -1)
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ func (imp *Importer) Import(name string, chT interface{}, dir Dir, size int) os.
|
|||
// err = imp.ImportNValues("name", ch, Recv, 1, 1)
|
||||
// if err != nil { log.Fatal(err) }
|
||||
// fmt.Printf("%+v\n", <-ch)
|
||||
func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, size, n int) os.Error {
|
||||
func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, size, n int) error {
|
||||
ch, err := checkChan(chT, dir)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -203,7 +203,7 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, size,
|
|||
defer imp.chanLock.Unlock()
|
||||
_, present := imp.names[name]
|
||||
if present {
|
||||
return os.NewError("channel name already being imported:" + name)
|
||||
return errors.New("channel name already being imported:" + name)
|
||||
}
|
||||
if size < 1 {
|
||||
size = 1
|
||||
|
@ -249,12 +249,12 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, size,
|
|||
|
||||
// Hangup disassociates the named channel from the Importer and closes
|
||||
// the channel. Messages in flight for the channel may be dropped.
|
||||
func (imp *Importer) Hangup(name string) os.Error {
|
||||
func (imp *Importer) Hangup(name string) error {
|
||||
imp.chanLock.Lock()
|
||||
defer imp.chanLock.Unlock()
|
||||
nc := imp.names[name]
|
||||
if nc == nil {
|
||||
return os.NewError("netchan import: hangup: no such channel: " + name)
|
||||
return errors.New("netchan import: hangup: no such channel: " + name)
|
||||
}
|
||||
delete(imp.names, name)
|
||||
delete(imp.chans, nc.id)
|
||||
|
@ -275,11 +275,11 @@ func (imp *Importer) unackedCount() int64 {
|
|||
// waits until all the importer's messages have been received.
|
||||
// If the timeout (measured in nanoseconds) is positive and Drain takes
|
||||
// longer than that to complete, an error is returned.
|
||||
func (imp *Importer) Drain(timeout int64) os.Error {
|
||||
func (imp *Importer) Drain(timeout int64) error {
|
||||
startTime := time.Nanoseconds()
|
||||
for imp.unackedCount() > 0 {
|
||||
if timeout > 0 && time.Nanoseconds()-startTime >= timeout {
|
||||
return os.NewError("timeout")
|
||||
return errors.New("timeout")
|
||||
}
|
||||
time.Sleep(100 * 1e6)
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ func TestErrorForIllegalChannel(t *testing.T) {
|
|||
}()
|
||||
select {
|
||||
case err = <-imp.Errors():
|
||||
if strings.Index(err.String(), "no such channel") < 0 {
|
||||
if strings.Index(err.Error(), "no such channel") < 0 {
|
||||
t.Error("wrong error for nonexistent channel:", err)
|
||||
}
|
||||
case <-timeout:
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package regexp
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -33,7 +32,7 @@ var good_re = []string{
|
|||
|
||||
type stringError struct {
|
||||
re string
|
||||
err os.Error
|
||||
err error
|
||||
}
|
||||
|
||||
var bad_re = []stringError{
|
||||
|
@ -52,10 +51,10 @@ var bad_re = []stringError{
|
|||
{`\x`, ErrBadBackslash},
|
||||
}
|
||||
|
||||
func compileTest(t *testing.T, expr string, error os.Error) *Regexp {
|
||||
func compileTest(t *testing.T, expr string, error error) *Regexp {
|
||||
re, err := Compile(expr)
|
||||
if err != error {
|
||||
t.Error("compiling `", expr, "`; unexpected error: ", err.String())
|
||||
t.Error("compiling `", expr, "`; unexpected error: ", err.Error())
|
||||
}
|
||||
return re
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ package regexp
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"utf8"
|
||||
)
|
||||
|
@ -81,7 +80,7 @@ var debug = false
|
|||
// Error is the local type for a parsing error.
|
||||
type Error string
|
||||
|
||||
func (e Error) String() string {
|
||||
func (e Error) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
|
@ -616,7 +615,7 @@ func (re *Regexp) String() string {
|
|||
|
||||
// Compile parses a regular expression and returns, if successful, a Regexp
|
||||
// object that can be used to match against text.
|
||||
func Compile(str string) (regexp *Regexp, error os.Error) {
|
||||
func Compile(str string) (regexp *Regexp, error error) {
|
||||
regexp = new(Regexp)
|
||||
// doParse will panic if there is a parse error.
|
||||
defer func() {
|
||||
|
@ -637,7 +636,7 @@ func Compile(str string) (regexp *Regexp, error os.Error) {
|
|||
func MustCompile(str string) *Regexp {
|
||||
regexp, error := Compile(str)
|
||||
if error != nil {
|
||||
panic(`regexp: compiling "` + str + `": ` + error.String())
|
||||
panic(`regexp: compiling "` + str + `": ` + error.Error())
|
||||
}
|
||||
return regexp
|
||||
}
|
||||
|
@ -998,7 +997,7 @@ func (re *Regexp) Match(b []byte) bool { return len(re.doExecute(newInputBytes(b
|
|||
// MatchReader checks whether a textual regular expression matches the text
|
||||
// read by the RuneReader. More complicated queries need to use Compile and
|
||||
// the full Regexp interface.
|
||||
func MatchReader(pattern string, r io.RuneReader) (matched bool, error os.Error) {
|
||||
func MatchReader(pattern string, r io.RuneReader) (matched bool, error error) {
|
||||
re, err := Compile(pattern)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -1009,7 +1008,7 @@ func MatchReader(pattern string, r io.RuneReader) (matched bool, error os.Error)
|
|||
// MatchString checks whether a textual regular expression
|
||||
// matches a string. More complicated queries need
|
||||
// to use Compile and the full Regexp interface.
|
||||
func MatchString(pattern string, s string) (matched bool, error os.Error) {
|
||||
func MatchString(pattern string, s string) (matched bool, error error) {
|
||||
re, err := Compile(pattern)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -1020,7 +1019,7 @@ func MatchString(pattern string, s string) (matched bool, error os.Error) {
|
|||
// Match checks whether a textual regular expression
|
||||
// matches a byte slice. More complicated queries need
|
||||
// to use Compile and the full Regexp interface.
|
||||
func Match(pattern string, b []byte) (matched bool, error os.Error) {
|
||||
func Match(pattern string, b []byte) (matched bool, error error) {
|
||||
re, err := Compile(pattern)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -25,11 +24,11 @@ type Error struct {
|
|||
Msg string
|
||||
}
|
||||
|
||||
func (e *Error) String() string { return fmt.Sprintf("line %d: %s", e.Line, e.Msg) }
|
||||
func (e *Error) Error() string { return fmt.Sprintf("line %d: %s", e.Line, e.Msg) }
|
||||
|
||||
// checkError is a deferred function to turn a panic with type *Error into a plain error return.
|
||||
// Other panics are unexpected and so are re-enabled.
|
||||
func checkError(error *os.Error) {
|
||||
func checkError(error *error) {
|
||||
if v := recover(); v != nil {
|
||||
if e, ok := v.(*Error); ok {
|
||||
*error = e
|
||||
|
@ -414,7 +413,7 @@ func (t *Template) newVariable(words []string) *variableElement {
|
|||
|
||||
// Build argument list, processing any literals
|
||||
for i, word := range words {
|
||||
var lerr os.Error
|
||||
var lerr error
|
||||
switch word[0] {
|
||||
case '"', '`', '\'':
|
||||
v, err := strconv.Unquote(word)
|
||||
|
@ -650,7 +649,7 @@ func (t *Template) parse() {
|
|||
// Parse initializes a Template by parsing its definition. The string
|
||||
// s contains the template text. If any errors occur, Parse returns
|
||||
// the error.
|
||||
func (t *Template) Parse(s string) (err os.Error) {
|
||||
func (t *Template) Parse(s string) (err error) {
|
||||
if t.elems == nil {
|
||||
return &Error{1, "template not allocated with New"}
|
||||
}
|
||||
|
@ -667,7 +666,7 @@ func (t *Template) Parse(s string) (err os.Error) {
|
|||
|
||||
// ParseFile is like Parse but reads the template definition from the
|
||||
// named file.
|
||||
func (t *Template) ParseFile(filename string) (err os.Error) {
|
||||
func (t *Template) ParseFile(filename string) (err error) {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -677,7 +676,7 @@ func (t *Template) ParseFile(filename string) (err os.Error) {
|
|||
|
||||
// Execute applies a parsed template to the specified data object,
|
||||
// generating output to wr.
|
||||
func (t *Template) Execute(wr io.Writer, data interface{}) (err os.Error) {
|
||||
func (t *Template) Execute(wr io.Writer, data interface{}) (err error) {
|
||||
// Extract the driver data.
|
||||
val := reflect.ValueOf(data)
|
||||
defer checkError(&err)
|
||||
|
@ -701,7 +700,7 @@ func (t *Template) SetDelims(left, right string) {
|
|||
// the formatter map fmap, which may be nil, defines auxiliary functions
|
||||
// for formatting variables. The template is returned. If any errors
|
||||
// occur, err will be non-nil.
|
||||
func Parse(s string, fmap FormatterMap) (t *Template, err os.Error) {
|
||||
func Parse(s string, fmap FormatterMap) (t *Template, err error) {
|
||||
t = New(fmap)
|
||||
err = t.Parse(s)
|
||||
if err != nil {
|
||||
|
@ -715,7 +714,7 @@ func Parse(s string, fmap FormatterMap) (t *Template, err os.Error) {
|
|||
// a file containing the template text, while the formatter map fmap, which
|
||||
// may be nil, defines auxiliary functions for formatting variables.
|
||||
// The template is returned. If any errors occur, err will be non-nil.
|
||||
func ParseFile(filename string, fmap FormatterMap) (t *Template, err os.Error) {
|
||||
func ParseFile(filename string, fmap FormatterMap) (t *Template, err error) {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -727,7 +726,7 @@ func ParseFile(filename string, fmap FormatterMap) (t *Template, err os.Error) {
|
|||
func MustParse(s string, fmap FormatterMap) *Template {
|
||||
t, err := Parse(s, fmap)
|
||||
if err != nil {
|
||||
panic("template.MustParse error: " + err.String())
|
||||
panic("template.MustParse error: " + err.Error())
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
@ -737,7 +736,7 @@ func MustParse(s string, fmap FormatterMap) *Template {
|
|||
func MustParseFile(filename string, fmap FormatterMap) *Template {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic("template.MustParseFile error: " + err.String())
|
||||
panic("template.MustParseFile error: " + err.Error())
|
||||
}
|
||||
return MustParse(string(b), fmap)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -462,9 +461,9 @@ var tests = []*Test{
|
|||
|
||||
func TestAll(t *testing.T) {
|
||||
// Parse
|
||||
testAll(t, func(test *Test) (*Template, os.Error) { return Parse(test.in, formatters) })
|
||||
testAll(t, func(test *Test) (*Template, error) { return Parse(test.in, formatters) })
|
||||
// ParseFile
|
||||
testAll(t, func(test *Test) (*Template, os.Error) {
|
||||
testAll(t, func(test *Test) (*Template, error) {
|
||||
err := ioutil.WriteFile("_test/test.tmpl", []byte(test.in), 0600)
|
||||
if err != nil {
|
||||
t.Error("unexpected write error:", err)
|
||||
|
@ -473,7 +472,7 @@ func TestAll(t *testing.T) {
|
|||
return ParseFile("_test/test.tmpl", formatters)
|
||||
})
|
||||
// tmpl.ParseFile
|
||||
testAll(t, func(test *Test) (*Template, os.Error) {
|
||||
testAll(t, func(test *Test) (*Template, error) {
|
||||
err := ioutil.WriteFile("_test/test.tmpl", []byte(test.in), 0600)
|
||||
if err != nil {
|
||||
t.Error("unexpected write error:", err)
|
||||
|
@ -484,7 +483,7 @@ func TestAll(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) {
|
||||
func testAll(t *testing.T, parseFunc func(*Test) (*Template, error)) {
|
||||
s := new(S)
|
||||
// initialized by hand for clarity.
|
||||
s.Header = "Header"
|
||||
|
@ -530,8 +529,8 @@ func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) {
|
|||
} else {
|
||||
if err == nil {
|
||||
t.Errorf("expected execute error %q, got nil", test.err)
|
||||
} else if err.String() != test.err {
|
||||
t.Errorf("expected execute error %q, got %q", test.err, err.String())
|
||||
} else if err.Error() != test.err {
|
||||
t.Errorf("expected execute error %q, got %q", test.err, err.Error())
|
||||
}
|
||||
}
|
||||
if buf.String() != test.out {
|
||||
|
@ -703,7 +702,7 @@ func TestReferenceToUnexported(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("expected execute error, got none")
|
||||
}
|
||||
if strings.Index(err.String(), "not exported") < 0 {
|
||||
if strings.Index(err.Error(), "not exported") < 0 {
|
||||
t.Fatal("expected unexported error; got", err)
|
||||
}
|
||||
}
|
||||
|
@ -777,8 +776,8 @@ func TestFormatters(t *testing.T) {
|
|||
t.Error("unexpected parse error:", err)
|
||||
continue
|
||||
}
|
||||
if strings.Index(err.String(), c.err) < 0 {
|
||||
t.Errorf("unexpected error: expected %q, got %q", c.err, err.String())
|
||||
if strings.Index(err.Error(), c.err) < 0 {
|
||||
t.Errorf("unexpected error: expected %q, got %q", c.err, err.Error())
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -8,14 +8,13 @@ package user
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func Lookup(username string) (*User, os.Error) {
|
||||
func Lookup(username string) (*User, error) {
|
||||
return nil, fmt.Errorf("user: Lookup not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
func LookupId(int) (*User, os.Error) {
|
||||
func LookupId(int) (*User, error) {
|
||||
return nil, fmt.Errorf("user: LookupId not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
|
|
@ -33,17 +33,17 @@ func init() {
|
|||
|
||||
// Lookup looks up a user by username. If the user cannot be found,
|
||||
// the returned error is of type UnknownUserError.
|
||||
func Lookup(username string) (*User, os.Error) {
|
||||
func Lookup(username string) (*User, error) {
|
||||
return lookup(-1, username, true)
|
||||
}
|
||||
|
||||
// LookupId looks up a user by userid. If the user cannot be found,
|
||||
// the returned error is of type UnknownUserIdError.
|
||||
func LookupId(uid int) (*User, os.Error) {
|
||||
func LookupId(uid int) (*User, error) {
|
||||
return lookup(uid, "", false)
|
||||
}
|
||||
|
||||
func lookup(uid int, username string, lookupByName bool) (*User, os.Error) {
|
||||
func lookup(uid int, username string, lookupByName bool) (*User, error) {
|
||||
var pwd C.struct_passwd
|
||||
var result *C.struct_passwd
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ type User struct {
|
|||
// a user cannot be found.
|
||||
type UnknownUserIdError int
|
||||
|
||||
func (e UnknownUserIdError) String() string {
|
||||
func (e UnknownUserIdError) Error() string {
|
||||
return "user: unknown userid " + strconv.Itoa(int(e))
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,6 @@ func (e UnknownUserIdError) String() string {
|
|||
// a user cannot be found.
|
||||
type UnknownUserError string
|
||||
|
||||
func (e UnknownUserError) String() string {
|
||||
func (e UnknownUserError) Error() string {
|
||||
return "user: unknown user " + string(e)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ type Op struct {
|
|||
// The function readFile should return the contents of the named file.
|
||||
// Typically this function will be io.ReadFile.
|
||||
//
|
||||
func (set *Set) Apply(readFile func(string) ([]byte, os.Error)) ([]Op, os.Error) {
|
||||
func (set *Set) Apply(readFile func(string) ([]byte, error)) ([]Op, error) {
|
||||
op := make([]Op, len(set.File))
|
||||
|
||||
for i, f := range set.File {
|
||||
|
@ -36,7 +36,7 @@ func (set *Set) Apply(readFile func(string) ([]byte, os.Error)) ([]Op, os.Error)
|
|||
// Clients assume o.Data == nil means no data diff.
|
||||
// Start with a non-nil data.
|
||||
var old []byte = make([]byte, 0) // not nil
|
||||
var err os.Error
|
||||
var err error
|
||||
if f.Src != "" {
|
||||
old, err = readFile(f.Src)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"compress/zlib"
|
||||
"crypto/sha1"
|
||||
"encoding/git85"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func gitSHA1(data []byte) []byte {
|
||||
|
@ -34,7 +34,7 @@ type GitBinaryLiteral struct {
|
|||
}
|
||||
|
||||
// Apply implements the Diff interface's Apply method.
|
||||
func (d *GitBinaryLiteral) Apply(old []byte) ([]byte, os.Error) {
|
||||
func (d *GitBinaryLiteral) Apply(old []byte) ([]byte, error) {
|
||||
if sum := gitSHA1(old); !bytes.HasPrefix(sum, d.OldSHA1) {
|
||||
return nil, ErrPatchFailure
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func getHex(s []byte) (data []byte, rest []byte) {
|
|||
}
|
||||
|
||||
// ParseGitBinary parses raw as a Git binary patch.
|
||||
func ParseGitBinary(raw []byte) (Diff, os.Error) {
|
||||
func ParseGitBinary(raw []byte) (Diff, error) {
|
||||
var oldSHA1, newSHA1 []byte
|
||||
var sawBinary bool
|
||||
|
||||
|
@ -97,24 +97,24 @@ func ParseGitBinary(raw []byte) (Diff, os.Error) {
|
|||
}
|
||||
defer z.Close()
|
||||
if _, err = io.ReadFull(z, data); err != nil {
|
||||
if err == os.EOF {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var buf [1]byte
|
||||
m, err := z.Read(buf[0:])
|
||||
if m != 0 || err != os.EOF {
|
||||
return nil, os.NewError("Git binary literal longer than expected")
|
||||
if m != 0 || err != io.EOF {
|
||||
return nil, errors.New("Git binary literal longer than expected")
|
||||
}
|
||||
|
||||
if sum := gitSHA1(data); !bytes.HasPrefix(sum, newSHA1) {
|
||||
return nil, os.NewError("Git binary literal SHA1 mismatch")
|
||||
return nil, errors.New("Git binary literal SHA1 mismatch")
|
||||
}
|
||||
return &GitBinaryLiteral{oldSHA1, data}, nil
|
||||
}
|
||||
if !sawBinary {
|
||||
return nil, os.NewError("unexpected Git patch header: " + string(first))
|
||||
return nil, errors.New("unexpected Git patch header: " + string(first))
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
|
|
|
@ -9,7 +9,6 @@ package patch
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
@ -47,7 +46,7 @@ type Diff interface {
|
|||
// Apply applies the changes listed in the diff
|
||||
// to the string s, returning the new version of the string.
|
||||
// Note that the string s need not be a text string.
|
||||
Apply(old []byte) (new []byte, err os.Error)
|
||||
Apply(old []byte) (new []byte, err error)
|
||||
}
|
||||
|
||||
// NoDiff is a no-op Diff implementation: it passes the
|
||||
|
@ -56,14 +55,14 @@ var NoDiff Diff = noDiffType(0)
|
|||
|
||||
type noDiffType int
|
||||
|
||||
func (noDiffType) Apply(old []byte) ([]byte, os.Error) {
|
||||
func (noDiffType) Apply(old []byte) ([]byte, error) {
|
||||
return old, nil
|
||||
}
|
||||
|
||||
// A SyntaxError represents a syntax error encountered while parsing a patch.
|
||||
type SyntaxError string
|
||||
|
||||
func (e SyntaxError) String() string { return string(e) }
|
||||
func (e SyntaxError) Error() string { return string(e) }
|
||||
|
||||
var newline = []byte{'\n'}
|
||||
|
||||
|
@ -71,7 +70,7 @@ var newline = []byte{'\n'}
|
|||
// The patch text typically comprises a textual header and a sequence
|
||||
// of file patches, as would be generated by CVS, Subversion,
|
||||
// Mercurial, or Git.
|
||||
func Parse(text []byte) (*Set, os.Error) {
|
||||
func Parse(text []byte) (*Set, error) {
|
||||
// Split text into files.
|
||||
// CVS and Subversion begin new files with
|
||||
// Index: file name.
|
||||
|
|
|
@ -2,7 +2,7 @@ package patch
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type TextDiff []TextChunk
|
||||
|
@ -16,7 +16,7 @@ type TextChunk struct {
|
|||
New []byte
|
||||
}
|
||||
|
||||
func ParseTextDiff(raw []byte) (TextDiff, os.Error) {
|
||||
func ParseTextDiff(raw []byte) (TextDiff, error) {
|
||||
var chunkHeader []byte
|
||||
|
||||
// Copy raw so it is safe to keep references to slices.
|
||||
|
@ -151,11 +151,11 @@ ErrChunkHdr:
|
|||
return nil, SyntaxError("unexpected chunk header line: " + string(chunkHeader))
|
||||
}
|
||||
|
||||
var ErrPatchFailure = os.NewError("patch did not apply cleanly")
|
||||
var ErrPatchFailure = errors.New("patch did not apply cleanly")
|
||||
|
||||
// Apply applies the changes listed in the diff
|
||||
// to the data, returning the new version.
|
||||
func (d TextDiff) Apply(data []byte) ([]byte, os.Error) {
|
||||
func (d TextDiff) Apply(data []byte) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
line := 1
|
||||
for _, c := range d {
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
package filepath
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"utf8"
|
||||
)
|
||||
|
||||
var ErrBadPattern = os.NewError("syntax error in pattern")
|
||||
var ErrBadPattern = errors.New("syntax error in pattern")
|
||||
|
||||
// Match returns true if name matches the shell file name pattern.
|
||||
// The pattern syntax is:
|
||||
|
@ -34,7 +35,7 @@ var ErrBadPattern = os.NewError("syntax error in pattern")
|
|||
// Match requires pattern to match all of name, not just a substring.
|
||||
// The only possible error return occurs when the pattern is malformed.
|
||||
//
|
||||
func Match(pattern, name string) (matched bool, err os.Error) {
|
||||
func Match(pattern, name string) (matched bool, err error) {
|
||||
Pattern:
|
||||
for len(pattern) > 0 {
|
||||
var star bool
|
||||
|
@ -112,7 +113,7 @@ Scan:
|
|||
// matchChunk checks whether chunk matches the beginning of s.
|
||||
// If so, it returns the remainder of s (after the match).
|
||||
// Chunk is all single-character operators: literals, char classes, and ?.
|
||||
func matchChunk(chunk, s string) (rest string, ok bool, err os.Error) {
|
||||
func matchChunk(chunk, s string) (rest string, ok bool, err error) {
|
||||
for len(chunk) > 0 {
|
||||
if len(s) == 0 {
|
||||
return
|
||||
|
@ -183,7 +184,7 @@ func matchChunk(chunk, s string) (rest string, ok bool, err os.Error) {
|
|||
}
|
||||
|
||||
// getEsc gets a possibly-escaped character from chunk, for a character class.
|
||||
func getEsc(chunk string) (r rune, nchunk string, err os.Error) {
|
||||
func getEsc(chunk string) (r rune, nchunk string, err error) {
|
||||
if len(chunk) == 0 || chunk[0] == '-' || chunk[0] == ']' {
|
||||
err = ErrBadPattern
|
||||
return
|
||||
|
@ -212,7 +213,7 @@ func getEsc(chunk string) (r rune, nchunk string, err os.Error) {
|
|||
// /usr/*/bin/ed (assuming the Separator is '/').
|
||||
// The only possible error return occurs when the pattern is malformed.
|
||||
//
|
||||
func Glob(pattern string) (matches []string, err os.Error) {
|
||||
func Glob(pattern string) (matches []string, err error) {
|
||||
if !hasMeta(pattern) {
|
||||
if _, err = os.Stat(pattern); err != nil {
|
||||
return nil, nil
|
||||
|
@ -253,7 +254,7 @@ func Glob(pattern string) (matches []string, err os.Error) {
|
|||
// opened, it returns the existing matches. New matches are
|
||||
// added in lexicographical order.
|
||||
// The only possible error return occurs when the pattern is malformed.
|
||||
func glob(dir, pattern string, matches []string) (m []string, e os.Error) {
|
||||
func glob(dir, pattern string, matches []string) (m []string, e error) {
|
||||
m = matches
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package filepath_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
. "path/filepath"
|
||||
"testing"
|
||||
"runtime"
|
||||
|
@ -14,7 +13,7 @@ import (
|
|||
type MatchTest struct {
|
||||
pattern, s string
|
||||
match bool
|
||||
err os.Error
|
||||
err error
|
||||
}
|
||||
|
||||
var matchTests = []MatchTest{
|
||||
|
@ -69,11 +68,11 @@ var matchTests = []MatchTest{
|
|||
{"*x", "xxx", true, nil},
|
||||
}
|
||||
|
||||
func errp(e os.Error) string {
|
||||
func errp(e error) string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return e.String()
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
func TestMatch(t *testing.T) {
|
||||
|
|
|
@ -8,6 +8,7 @@ package filepath
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"runtime"
|
||||
"sort"
|
||||
|
@ -182,7 +183,7 @@ func Ext(path string) string {
|
|||
// EvalSymlinks returns the path name after the evaluation of any symbolic
|
||||
// links.
|
||||
// If path is relative it will be evaluated relative to the current directory.
|
||||
func EvalSymlinks(path string) (string, os.Error) {
|
||||
func EvalSymlinks(path string) (string, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
// Symlinks are not supported under windows.
|
||||
_, err := os.Lstat(path)
|
||||
|
@ -198,7 +199,7 @@ func EvalSymlinks(path string) (string, os.Error) {
|
|||
var b bytes.Buffer
|
||||
for n := 0; path != ""; n++ {
|
||||
if n > maxIter {
|
||||
return "", os.NewError("EvalSymlinks: too many links in " + originalPath)
|
||||
return "", errors.New("EvalSymlinks: too many links in " + originalPath)
|
||||
}
|
||||
|
||||
// find next path component, p
|
||||
|
@ -247,7 +248,7 @@ func EvalSymlinks(path string) (string, os.Error) {
|
|||
// If the path is not absolute it will be joined with the current
|
||||
// working directory to turn it into an absolute path. The absolute
|
||||
// path name for a given file is not guaranteed to be unique.
|
||||
func Abs(path string) (string, os.Error) {
|
||||
func Abs(path string) (string, error) {
|
||||
if IsAbs(path) {
|
||||
return Clean(path), nil
|
||||
}
|
||||
|
@ -263,7 +264,7 @@ func Abs(path string) (string, os.Error) {
|
|||
// Join(basepath, Rel(basepath, targpath)) is equivalent to targpath itself.
|
||||
// An error is returned if targpath can't be made relative to basepath or if
|
||||
// knowing the current working directory would be necessary to compute it.
|
||||
func Rel(basepath, targpath string) (string, os.Error) {
|
||||
func Rel(basepath, targpath string) (string, error) {
|
||||
baseVol := VolumeName(basepath)
|
||||
targVol := VolumeName(targpath)
|
||||
base := Clean(basepath)
|
||||
|
@ -280,7 +281,7 @@ func Rel(basepath, targpath string) (string, os.Error) {
|
|||
baseSlashed := len(base) > 0 && base[0] == Separator
|
||||
targSlashed := len(targ) > 0 && targ[0] == Separator
|
||||
if baseSlashed != targSlashed || baseVol != targVol {
|
||||
return "", os.NewError("Rel: can't make " + targ + " relative to " + base)
|
||||
return "", errors.New("Rel: can't make " + targ + " relative to " + base)
|
||||
}
|
||||
// Position base[b0:bi] and targ[t0:ti] at the first differing elements.
|
||||
bl := len(base)
|
||||
|
@ -306,7 +307,7 @@ func Rel(basepath, targpath string) (string, os.Error) {
|
|||
t0 = ti
|
||||
}
|
||||
if base[b0:bi] == ".." {
|
||||
return "", os.NewError("Rel: can't make " + targ + " relative to " + base)
|
||||
return "", errors.New("Rel: can't make " + targ + " relative to " + base)
|
||||
}
|
||||
if b0 != bl {
|
||||
// Base elements left. Must go up before going down.
|
||||
|
@ -330,7 +331,7 @@ func Rel(basepath, targpath string) (string, os.Error) {
|
|||
// SkipDir is used as a return value from WalkFuncs to indicate that
|
||||
// the directory named in the call is to be skipped. It is not returned
|
||||
// as an error by any function.
|
||||
var SkipDir = os.NewError("skip this directory")
|
||||
var SkipDir = errors.New("skip this directory")
|
||||
|
||||
// WalkFunc is the type of the function called for each file or directory
|
||||
// visited by Walk. If there was a problem walking to the file or directory
|
||||
|
@ -340,10 +341,10 @@ var SkipDir = os.NewError("skip this directory")
|
|||
// sole exception is that if path is a directory and the function returns the
|
||||
// special value SkipDir, the contents of the directory are skipped
|
||||
// and processing continues as usual on the next file.
|
||||
type WalkFunc func(path string, info *os.FileInfo, err os.Error) os.Error
|
||||
type WalkFunc func(path string, info *os.FileInfo, err error) error
|
||||
|
||||
// walk recursively descends path, calling w.
|
||||
func walk(path string, info *os.FileInfo, walkFn WalkFunc) os.Error {
|
||||
func walk(path string, info *os.FileInfo, walkFn WalkFunc) error {
|
||||
err := walkFn(path, info, nil)
|
||||
if err != nil {
|
||||
if info.IsDirectory() && err == SkipDir {
|
||||
|
@ -374,7 +375,7 @@ func walk(path string, info *os.FileInfo, walkFn WalkFunc) os.Error {
|
|||
// and directories are filtered by walkFn. The files are walked in lexical
|
||||
// order, which makes the output deterministic but means that for very
|
||||
// large directories Walk can be inefficient.
|
||||
func Walk(root string, walkFn WalkFunc) os.Error {
|
||||
func Walk(root string, walkFn WalkFunc) error {
|
||||
info, err := os.Lstat(root)
|
||||
if err != nil {
|
||||
return walkFn(root, nil, err)
|
||||
|
@ -385,7 +386,7 @@ func Walk(root string, walkFn WalkFunc) os.Error {
|
|||
// readDir reads the directory named by dirname and returns
|
||||
// a sorted list of directory entries.
|
||||
// Copied from io/ioutil to avoid the circular import.
|
||||
func readDir(dirname string) ([]*os.FileInfo, os.Error) {
|
||||
func readDir(dirname string) ([]*os.FileInfo, error) {
|
||||
f, err := os.Open(dirname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -318,7 +318,7 @@ func checkMarks(t *testing.T, report bool) {
|
|||
// Assumes that each node name is unique. Good enough for a test.
|
||||
// If clear is true, any incoming error is cleared before return. The errors
|
||||
// are always accumulated, though.
|
||||
func mark(path string, info *os.FileInfo, err os.Error, errors *[]os.Error, clear bool) os.Error {
|
||||
func mark(path string, info *os.FileInfo, err error, errors *[]error, clear bool) error {
|
||||
if err != nil {
|
||||
*errors = append(*errors, err)
|
||||
if clear {
|
||||
|
@ -336,9 +336,9 @@ func mark(path string, info *os.FileInfo, err os.Error, errors *[]os.Error, clea
|
|||
|
||||
func TestWalk(t *testing.T) {
|
||||
makeTree(t)
|
||||
errors := make([]os.Error, 0, 10)
|
||||
errors := make([]error, 0, 10)
|
||||
clear := true
|
||||
markFn := func(path string, info *os.FileInfo, err os.Error) os.Error {
|
||||
markFn := func(path string, info *os.FileInfo, err error) error {
|
||||
return mark(path, info, err, &errors, clear)
|
||||
}
|
||||
// Expect no errors.
|
||||
|
@ -523,7 +523,7 @@ func testEvalSymlinks(t *testing.T, tests []EvalSymlinksTest) {
|
|||
func TestEvalSymlinks(t *testing.T) {
|
||||
defer os.RemoveAll("test")
|
||||
for _, d := range EvalSymlinksTestDirs {
|
||||
var err os.Error
|
||||
var err error
|
||||
if d.dest == "" {
|
||||
err = os.Mkdir(d.path, 0755)
|
||||
} else {
|
||||
|
@ -582,7 +582,7 @@ var abstests = []string{
|
|||
func TestAbs(t *testing.T) {
|
||||
oldwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal("Getwd failed: " + err.String())
|
||||
t.Fatal("Getwd failed: " + err.Error())
|
||||
}
|
||||
defer os.Chdir(oldwd)
|
||||
goroot := os.Getenv("GOROOT")
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
package path
|
||||
|
||||
import (
|
||||
"os"
|
||||
"errors"
|
||||
"strings"
|
||||
"utf8"
|
||||
)
|
||||
|
||||
var ErrBadPattern = os.NewError("syntax error in pattern")
|
||||
var ErrBadPattern = errors.New("syntax error in pattern")
|
||||
|
||||
// Match returns true if name matches the shell file name pattern.
|
||||
// The pattern syntax is:
|
||||
|
@ -33,7 +33,7 @@ var ErrBadPattern = os.NewError("syntax error in pattern")
|
|||
// Match requires pattern to match all of name, not just a substring.
|
||||
// The only possible error return is when pattern is malformed.
|
||||
//
|
||||
func Match(pattern, name string) (matched bool, err os.Error) {
|
||||
func Match(pattern, name string) (matched bool, err error) {
|
||||
Pattern:
|
||||
for len(pattern) > 0 {
|
||||
var star bool
|
||||
|
@ -111,7 +111,7 @@ Scan:
|
|||
// matchChunk checks whether chunk matches the beginning of s.
|
||||
// If so, it returns the remainder of s (after the match).
|
||||
// Chunk is all single-character operators: literals, char classes, and ?.
|
||||
func matchChunk(chunk, s string) (rest string, ok bool, err os.Error) {
|
||||
func matchChunk(chunk, s string) (rest string, ok bool, err error) {
|
||||
for len(chunk) > 0 {
|
||||
if len(s) == 0 {
|
||||
return
|
||||
|
@ -183,7 +183,7 @@ func matchChunk(chunk, s string) (rest string, ok bool, err os.Error) {
|
|||
}
|
||||
|
||||
// getEsc gets a possibly-escaped character from chunk, for a character class.
|
||||
func getEsc(chunk string) (r rune, nchunk string, err os.Error) {
|
||||
func getEsc(chunk string) (r rune, nchunk string, err error) {
|
||||
if len(chunk) == 0 || chunk[0] == '-' || chunk[0] == ']' {
|
||||
err = ErrBadPattern
|
||||
return
|
||||
|
|
|
@ -4,15 +4,12 @@
|
|||
|
||||
package path
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
type MatchTest struct {
|
||||
pattern, s string
|
||||
match bool
|
||||
err os.Error
|
||||
err error
|
||||
}
|
||||
|
||||
var matchTests = []MatchTest{
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
package rand
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -41,16 +41,16 @@ var testSeeds = []int64{1, 1754801282, 1698661970, 1550503961}
|
|||
|
||||
// checkSimilarDistribution returns success if the mean and stddev of the
|
||||
// two statsResults are similar.
|
||||
func (this *statsResults) checkSimilarDistribution(expected *statsResults) os.Error {
|
||||
func (this *statsResults) checkSimilarDistribution(expected *statsResults) error {
|
||||
if !nearEqual(this.mean, expected.mean, expected.closeEnough, expected.maxError) {
|
||||
s := fmt.Sprintf("mean %v != %v (allowed error %v, %v)", this.mean, expected.mean, expected.closeEnough, expected.maxError)
|
||||
fmt.Println(s)
|
||||
return os.NewError(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
if !nearEqual(this.stddev, expected.stddev, 0, expected.maxError) {
|
||||
s := fmt.Sprintf("stddev %v != %v (allowed error %v, %v)", this.stddev, expected.stddev, expected.closeEnough, expected.maxError)
|
||||
fmt.Println(s)
|
||||
return os.NewError(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func checkSampleDistribution(t *testing.T, samples []float64, expected *statsRes
|
|||
actual := getStatsResults(samples)
|
||||
err := actual.checkSimilarDistribution(expected)
|
||||
if err != nil {
|
||||
t.Errorf(err.String())
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -631,7 +631,7 @@ var deepEqualTests = []DeepEqualTest{
|
|||
{make([]int, 10), make([]int, 10), true},
|
||||
{&[3]int{1, 2, 3}, &[3]int{1, 2, 3}, true},
|
||||
{Basic{1, 0.5}, Basic{1, 0.5}, true},
|
||||
{os.Error(nil), os.Error(nil), true},
|
||||
{error(nil), error(nil), true},
|
||||
{map[int]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, true},
|
||||
|
||||
// Inequalities
|
||||
|
|
|
@ -71,7 +71,7 @@ type ValueError struct {
|
|||
Kind Kind
|
||||
}
|
||||
|
||||
func (e *ValueError) String() string {
|
||||
func (e *ValueError) Error() string {
|
||||
if e.Kind == 0 {
|
||||
return "reflect: call of " + e.Method + " on zero Value"
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package regexp
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -53,10 +52,10 @@ var bad_re = []stringError{
|
|||
}
|
||||
*/
|
||||
|
||||
func compileTest(t *testing.T, expr string, error os.Error) *Regexp {
|
||||
func compileTest(t *testing.T, expr string, error error) *Regexp {
|
||||
re, err := Compile(expr)
|
||||
if err != error {
|
||||
t.Error("compiling `", expr, "`; unexpected error: ", err.String())
|
||||
t.Error("compiling `", expr, "`; unexpected error: ", err.Error())
|
||||
}
|
||||
return re
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ func testRE2(t *testing.T, file string) {
|
|||
for {
|
||||
line, err := r.ReadString('\n')
|
||||
if err != nil {
|
||||
if err == os.EOF {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
t.Fatalf("%s:%d: %v", file, lineno, err)
|
||||
|
@ -141,7 +141,7 @@ func testRE2(t *testing.T, file string) {
|
|||
}
|
||||
re, err = tryCompile(q)
|
||||
if err != nil {
|
||||
if err.String() == "error parsing regexp: invalid escape sequence: `\\C`" {
|
||||
if err.Error() == "error parsing regexp: invalid escape sequence: `\\C`" {
|
||||
// We don't and likely never will support \C; keep going.
|
||||
continue
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ func isSingleBytes(s string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func tryCompile(s string) (re *Regexp, err os.Error) {
|
||||
func tryCompile(s string) (re *Regexp, err error) {
|
||||
// Protect against panic during Compile.
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -370,7 +370,7 @@ Reading:
|
|||
lineno++
|
||||
line, err := b.ReadString('\n')
|
||||
if err != nil {
|
||||
if err != os.EOF {
|
||||
if err != io.EOF {
|
||||
t.Errorf("%s:%d: %v", file, lineno, err)
|
||||
}
|
||||
break Reading
|
||||
|
@ -629,7 +629,7 @@ func parseFowlerResult(s string) (ok, compiled, matched bool, pos []int) {
|
|||
return
|
||||
}
|
||||
var v = -1
|
||||
var err os.Error
|
||||
var err error
|
||||
if s[:i] != "?" {
|
||||
v, err = strconv.Atoi(s[:i])
|
||||
if err != nil {
|
||||
|
|
|
@ -56,7 +56,6 @@ package regexp
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"regexp/syntax"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -69,7 +68,7 @@ var debug = false
|
|||
// Error is the local type for a parsing error.
|
||||
type Error string
|
||||
|
||||
func (e Error) String() string {
|
||||
func (e Error) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
|
@ -108,7 +107,7 @@ func (re *Regexp) String() string {
|
|||
// that Perl, Python, and other implementations use, although this
|
||||
// package implements it without the expense of backtracking.
|
||||
// For POSIX leftmost-longest matching, see CompilePOSIX.
|
||||
func Compile(expr string) (*Regexp, os.Error) {
|
||||
func Compile(expr string) (*Regexp, error) {
|
||||
return compile(expr, syntax.Perl, false)
|
||||
}
|
||||
|
||||
|
@ -131,11 +130,11 @@ func Compile(expr string) (*Regexp, os.Error) {
|
|||
// subexpression, then the second, and so on from left to right.
|
||||
// The POSIX rule is computationally prohibitive and not even well-defined.
|
||||
// See http://swtch.com/~rsc/regexp/regexp2.html#posix for details.
|
||||
func CompilePOSIX(expr string) (*Regexp, os.Error) {
|
||||
func CompilePOSIX(expr string) (*Regexp, error) {
|
||||
return compile(expr, syntax.POSIX, true)
|
||||
}
|
||||
|
||||
func compile(expr string, mode syntax.Flags, longest bool) (*Regexp, os.Error) {
|
||||
func compile(expr string, mode syntax.Flags, longest bool) (*Regexp, error) {
|
||||
re, err := syntax.Parse(expr, mode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -196,7 +195,7 @@ func (re *Regexp) put(z *machine) {
|
|||
func MustCompile(str string) *Regexp {
|
||||
regexp, error := Compile(str)
|
||||
if error != nil {
|
||||
panic(`regexp: Compile(` + quote(str) + `): ` + error.String())
|
||||
panic(`regexp: Compile(` + quote(str) + `): ` + error.Error())
|
||||
}
|
||||
return regexp
|
||||
}
|
||||
|
@ -207,7 +206,7 @@ func MustCompile(str string) *Regexp {
|
|||
func MustCompilePOSIX(str string) *Regexp {
|
||||
regexp, error := CompilePOSIX(str)
|
||||
if error != nil {
|
||||
panic(`regexp: CompilePOSIX(` + quote(str) + `): ` + error.String())
|
||||
panic(`regexp: CompilePOSIX(` + quote(str) + `): ` + error.Error())
|
||||
}
|
||||
return regexp
|
||||
}
|
||||
|
@ -392,7 +391,7 @@ func (re *Regexp) Match(b []byte) bool {
|
|||
// MatchReader checks whether a textual regular expression matches the text
|
||||
// read by the RuneReader. More complicated queries need to use Compile and
|
||||
// the full Regexp interface.
|
||||
func MatchReader(pattern string, r io.RuneReader) (matched bool, error os.Error) {
|
||||
func MatchReader(pattern string, r io.RuneReader) (matched bool, error error) {
|
||||
re, err := Compile(pattern)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -403,7 +402,7 @@ func MatchReader(pattern string, r io.RuneReader) (matched bool, error os.Error)
|
|||
// MatchString checks whether a textual regular expression
|
||||
// matches a string. More complicated queries need
|
||||
// to use Compile and the full Regexp interface.
|
||||
func MatchString(pattern string, s string) (matched bool, error os.Error) {
|
||||
func MatchString(pattern string, s string) (matched bool, error error) {
|
||||
re, err := Compile(pattern)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -414,7 +413,7 @@ func MatchString(pattern string, s string) (matched bool, error os.Error) {
|
|||
// Match checks whether a textual regular expression
|
||||
// matches a byte slice. More complicated queries need
|
||||
// to use Compile and the full Regexp interface.
|
||||
func Match(pattern string, b []byte) (matched bool, error os.Error) {
|
||||
func Match(pattern string, b []byte) (matched bool, error error) {
|
||||
re, err := Compile(pattern)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package syntax
|
||||
|
||||
import (
|
||||
"os"
|
||||
"unicode"
|
||||
)
|
||||
import "unicode"
|
||||
|
||||
// A patchList is a list of instruction pointers that need to be filled in (patched).
|
||||
// Because the pointers haven't been filled in yet, we can reuse their storage
|
||||
|
@ -76,7 +73,7 @@ type compiler struct {
|
|||
|
||||
// Compile compiles the regexp into a program to be executed.
|
||||
// The regexp should have been simplified already (returned from re.Simplify).
|
||||
func Compile(re *Regexp) (*Prog, os.Error) {
|
||||
func Compile(re *Regexp) (*Prog, error) {
|
||||
var c compiler
|
||||
c.init()
|
||||
f := c.compile(re)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package syntax
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
@ -19,7 +18,7 @@ type Error struct {
|
|||
Expr string
|
||||
}
|
||||
|
||||
func (e *Error) String() string {
|
||||
func (e *Error) Error() string {
|
||||
return "error parsing regexp: " + e.Code.String() + ": `" + e.Expr + "`"
|
||||
}
|
||||
|
||||
|
@ -222,7 +221,7 @@ func (p *parser) op(op Op) *Regexp {
|
|||
// before is the regexp suffix starting at the repetition operator.
|
||||
// after is the regexp suffix following after the repetition operator.
|
||||
// repeat returns an updated 'after' and an error, if any.
|
||||
func (p *parser) repeat(op Op, min, max int, before, after, lastRepeat string) (string, os.Error) {
|
||||
func (p *parser) repeat(op Op, min, max int, before, after, lastRepeat string) (string, error) {
|
||||
flags := p.flags
|
||||
if p.flags&PerlX != 0 {
|
||||
if len(after) > 0 && after[0] == '?' {
|
||||
|
@ -649,7 +648,7 @@ func literalRegexp(s string, flags Flags) *Regexp {
|
|||
|
||||
// Parsing.
|
||||
|
||||
func Parse(s string, flags Flags) (*Regexp, os.Error) {
|
||||
func Parse(s string, flags Flags) (*Regexp, error) {
|
||||
if flags&Literal != 0 {
|
||||
// Trivial parser for literal string.
|
||||
if err := checkUTF8(s); err != nil {
|
||||
|
@ -661,7 +660,7 @@ func Parse(s string, flags Flags) (*Regexp, os.Error) {
|
|||
// Otherwise, must do real work.
|
||||
var (
|
||||
p parser
|
||||
err os.Error
|
||||
err error
|
||||
c rune
|
||||
op Op
|
||||
lastRepeat string
|
||||
|
@ -889,7 +888,7 @@ func (p *parser) parseRepeat(s string) (min, max int, rest string, ok bool) {
|
|||
// parsePerlFlags parses a Perl flag setting or non-capturing group or both,
|
||||
// like (?i) or (?: or (?i:. It removes the prefix from s and updates the parse state.
|
||||
// The caller must have ensured that s begins with "(?".
|
||||
func (p *parser) parsePerlFlags(s string) (rest string, err os.Error) {
|
||||
func (p *parser) parsePerlFlags(s string) (rest string, err error) {
|
||||
t := s
|
||||
|
||||
// Check for named captures, first introduced in Python's regexp library.
|
||||
|
@ -1069,7 +1068,7 @@ func matchRune(re *Regexp, r rune) bool {
|
|||
}
|
||||
|
||||
// parseVerticalBar handles a | in the input.
|
||||
func (p *parser) parseVerticalBar() os.Error {
|
||||
func (p *parser) parseVerticalBar() error {
|
||||
p.concat()
|
||||
|
||||
// The concatenation we just parsed is on top of the stack.
|
||||
|
@ -1152,7 +1151,7 @@ func (p *parser) swapVerticalBar() bool {
|
|||
}
|
||||
|
||||
// parseRightParen handles a ) in the input.
|
||||
func (p *parser) parseRightParen() os.Error {
|
||||
func (p *parser) parseRightParen() error {
|
||||
p.concat()
|
||||
if p.swapVerticalBar() {
|
||||
// pop vertical bar
|
||||
|
@ -1186,7 +1185,7 @@ func (p *parser) parseRightParen() os.Error {
|
|||
|
||||
// parseEscape parses an escape sequence at the beginning of s
|
||||
// and returns the rune.
|
||||
func (p *parser) parseEscape(s string) (r rune, rest string, err os.Error) {
|
||||
func (p *parser) parseEscape(s string) (r rune, rest string, err error) {
|
||||
t := s[1:]
|
||||
if t == "" {
|
||||
return 0, "", &Error{ErrTrailingBackslash, ""}
|
||||
|
@ -1302,7 +1301,7 @@ Switch:
|
|||
|
||||
// parseClassChar parses a character class character at the beginning of s
|
||||
// and returns it.
|
||||
func (p *parser) parseClassChar(s, wholeClass string) (r rune, rest string, err os.Error) {
|
||||
func (p *parser) parseClassChar(s, wholeClass string) (r rune, rest string, err error) {
|
||||
if s == "" {
|
||||
return 0, "", &Error{Code: ErrMissingBracket, Expr: wholeClass}
|
||||
}
|
||||
|
@ -1338,7 +1337,7 @@ func (p *parser) parsePerlClassEscape(s string, r []rune) (out []rune, rest stri
|
|||
// parseNamedClass parses a leading POSIX named character class like [:alnum:]
|
||||
// from the beginning of s. If one is present, it appends the characters to r
|
||||
// and returns the new slice r and the remainder of the string.
|
||||
func (p *parser) parseNamedClass(s string, r []rune) (out []rune, rest string, err os.Error) {
|
||||
func (p *parser) parseNamedClass(s string, r []rune) (out []rune, rest string, err error) {
|
||||
if len(s) < 2 || s[0] != '[' || s[1] != ':' {
|
||||
return
|
||||
}
|
||||
|
@ -1401,7 +1400,7 @@ func unicodeTable(name string) (*unicode.RangeTable, *unicode.RangeTable) {
|
|||
// parseUnicodeClass parses a leading Unicode character class like \p{Han}
|
||||
// from the beginning of s. If one is present, it appends the characters to r
|
||||
// and returns the new slice r and the remainder of the string.
|
||||
func (p *parser) parseUnicodeClass(s string, r []rune) (out []rune, rest string, err os.Error) {
|
||||
func (p *parser) parseUnicodeClass(s string, r []rune) (out []rune, rest string, err error) {
|
||||
if p.flags&UnicodeGroups == 0 || len(s) < 2 || s[0] != '\\' || s[1] != 'p' && s[1] != 'P' {
|
||||
return
|
||||
}
|
||||
|
@ -1474,7 +1473,7 @@ func (p *parser) parseUnicodeClass(s string, r []rune) (out []rune, rest string,
|
|||
|
||||
// parseClass parses a character class at the beginning of s
|
||||
// and pushes it onto the parse stack.
|
||||
func (p *parser) parseClass(s string) (rest string, err os.Error) {
|
||||
func (p *parser) parseClass(s string) (rest string, err error) {
|
||||
t := s[1:] // chop [
|
||||
re := p.newRegexp(OpCharClass)
|
||||
re.Flags = p.flags
|
||||
|
@ -1824,7 +1823,7 @@ func (ra ranges) Swap(i, j int) {
|
|||
p[i], p[i+1], p[j], p[j+1] = p[j], p[j+1], p[i], p[i+1]
|
||||
}
|
||||
|
||||
func checkUTF8(s string) os.Error {
|
||||
func checkUTF8(s string) error {
|
||||
for s != "" {
|
||||
rune, size := utf8.DecodeRuneInString(s)
|
||||
if rune == utf8.RuneError && size == 1 {
|
||||
|
@ -1835,7 +1834,7 @@ func checkUTF8(s string) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func nextRune(s string) (c rune, t string, err os.Error) {
|
||||
func nextRune(s string) (c rune, t string, err error) {
|
||||
c, size := utf8.DecodeRuneInString(s)
|
||||
if c == utf8.RuneError && size == 1 {
|
||||
return 0, "", &Error{Code: ErrInvalidUTF8, Expr: s}
|
||||
|
|
|
@ -6,12 +6,12 @@ package rpc
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"gob"
|
||||
"http"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -19,18 +19,18 @@ import (
|
|||
// the remote side of the RPC connection.
|
||||
type ServerError string
|
||||
|
||||
func (e ServerError) String() string {
|
||||
func (e ServerError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
var ErrShutdown = os.NewError("connection is shut down")
|
||||
var ErrShutdown = errors.New("connection is shut down")
|
||||
|
||||
// Call represents an active RPC.
|
||||
type Call struct {
|
||||
ServiceMethod string // The name of the service and method to call.
|
||||
Args interface{} // The argument to the function (*struct).
|
||||
Reply interface{} // The reply from the function (*struct).
|
||||
Error os.Error // After completion, the error status.
|
||||
Error error // After completion, the error status.
|
||||
Done chan *Call // Strobes when call is complete; value is the error status.
|
||||
seq uint64
|
||||
}
|
||||
|
@ -58,11 +58,11 @@ type Client struct {
|
|||
// argument to force the body of the response to be read and then
|
||||
// discarded.
|
||||
type ClientCodec interface {
|
||||
WriteRequest(*Request, interface{}) os.Error
|
||||
ReadResponseHeader(*Response) os.Error
|
||||
ReadResponseBody(interface{}) os.Error
|
||||
WriteRequest(*Request, interface{}) error
|
||||
ReadResponseHeader(*Response) error
|
||||
ReadResponseBody(interface{}) error
|
||||
|
||||
Close() os.Error
|
||||
Close() error
|
||||
}
|
||||
|
||||
func (client *Client) send(c *Call) {
|
||||
|
@ -91,13 +91,13 @@ func (client *Client) send(c *Call) {
|
|||
}
|
||||
|
||||
func (client *Client) input() {
|
||||
var err os.Error
|
||||
var err error
|
||||
var response Response
|
||||
for err == nil {
|
||||
response = Response{}
|
||||
err = client.codec.ReadResponseHeader(&response)
|
||||
if err != nil {
|
||||
if err == os.EOF && !client.closing {
|
||||
if err == io.EOF && !client.closing {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
break
|
||||
|
@ -111,7 +111,7 @@ func (client *Client) input() {
|
|||
if response.Error == "" {
|
||||
err = client.codec.ReadResponseBody(c.Reply)
|
||||
if err != nil {
|
||||
c.Error = os.NewError("reading body " + err.String())
|
||||
c.Error = errors.New("reading body " + err.Error())
|
||||
}
|
||||
} else {
|
||||
// We've got an error response. Give this to the request;
|
||||
|
@ -120,7 +120,7 @@ func (client *Client) input() {
|
|||
c.Error = ServerError(response.Error)
|
||||
err = client.codec.ReadResponseBody(nil)
|
||||
if err != nil {
|
||||
err = os.NewError("reading error body: " + err.String())
|
||||
err = errors.New("reading error body: " + err.Error())
|
||||
}
|
||||
}
|
||||
c.done()
|
||||
|
@ -133,7 +133,7 @@ func (client *Client) input() {
|
|||
call.done()
|
||||
}
|
||||
client.mutex.Unlock()
|
||||
if err != os.EOF || !client.closing {
|
||||
if err != io.EOF || !client.closing {
|
||||
log.Println("rpc: client protocol error:", err)
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ type gobClientCodec struct {
|
|||
encBuf *bufio.Writer
|
||||
}
|
||||
|
||||
func (c *gobClientCodec) WriteRequest(r *Request, body interface{}) (err os.Error) {
|
||||
func (c *gobClientCodec) WriteRequest(r *Request, body interface{}) (err error) {
|
||||
if err = c.enc.Encode(r); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -186,28 +186,28 @@ func (c *gobClientCodec) WriteRequest(r *Request, body interface{}) (err os.Erro
|
|||
return c.encBuf.Flush()
|
||||
}
|
||||
|
||||
func (c *gobClientCodec) ReadResponseHeader(r *Response) os.Error {
|
||||
func (c *gobClientCodec) ReadResponseHeader(r *Response) error {
|
||||
return c.dec.Decode(r)
|
||||
}
|
||||
|
||||
func (c *gobClientCodec) ReadResponseBody(body interface{}) os.Error {
|
||||
func (c *gobClientCodec) ReadResponseBody(body interface{}) error {
|
||||
return c.dec.Decode(body)
|
||||
}
|
||||
|
||||
func (c *gobClientCodec) Close() os.Error {
|
||||
func (c *gobClientCodec) Close() error {
|
||||
return c.rwc.Close()
|
||||
}
|
||||
|
||||
// DialHTTP connects to an HTTP RPC server at the specified network address
|
||||
// listening on the default HTTP RPC path.
|
||||
func DialHTTP(network, address string) (*Client, os.Error) {
|
||||
func DialHTTP(network, address string) (*Client, error) {
|
||||
return DialHTTPPath(network, address, DefaultRPCPath)
|
||||
}
|
||||
|
||||
// DialHTTPPath connects to an HTTP RPC server
|
||||
// at the specified network address and path.
|
||||
func DialHTTPPath(network, address, path string) (*Client, os.Error) {
|
||||
var err os.Error
|
||||
func DialHTTPPath(network, address, path string) (*Client, error) {
|
||||
var err error
|
||||
conn, err := net.Dial(network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -221,14 +221,14 @@ func DialHTTPPath(network, address, path string) (*Client, os.Error) {
|
|||
return NewClient(conn), nil
|
||||
}
|
||||
if err == nil {
|
||||
err = os.NewError("unexpected HTTP response: " + resp.Status)
|
||||
err = errors.New("unexpected HTTP response: " + resp.Status)
|
||||
}
|
||||
conn.Close()
|
||||
return nil, &net.OpError{"dial-http", network + " " + address, nil, err}
|
||||
}
|
||||
|
||||
// Dial connects to an RPC server at the specified network address.
|
||||
func Dial(network, address string) (*Client, os.Error) {
|
||||
func Dial(network, address string) (*Client, error) {
|
||||
conn, err := net.Dial(network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -236,7 +236,7 @@ func Dial(network, address string) (*Client, os.Error) {
|
|||
return NewClient(conn), nil
|
||||
}
|
||||
|
||||
func (client *Client) Close() os.Error {
|
||||
func (client *Client) Close() error {
|
||||
client.mutex.Lock()
|
||||
if client.shutdown || client.closing {
|
||||
client.mutex.Unlock()
|
||||
|
@ -278,7 +278,7 @@ func (client *Client) Go(serviceMethod string, args interface{}, reply interface
|
|||
}
|
||||
|
||||
// Call invokes the named function, waits for it to complete, and returns its error status.
|
||||
func (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) os.Error {
|
||||
func (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
if client.shutdown {
|
||||
return ErrShutdown
|
||||
}
|
||||
|
|
|
@ -85,6 +85,6 @@ func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
sort.Sort(services)
|
||||
err := debug.Execute(w, services)
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "rpc: error executing template:", err.String())
|
||||
fmt.Fprintln(w, "rpc: error executing template:", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
package jsonrpc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"json"
|
||||
"net"
|
||||
"os"
|
||||
"rpc"
|
||||
"testing"
|
||||
)
|
||||
|
@ -24,25 +24,25 @@ type Reply struct {
|
|||
|
||||
type Arith int
|
||||
|
||||
func (t *Arith) Add(args *Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Add(args *Args, reply *Reply) error {
|
||||
reply.C = args.A + args.B
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) Mul(args *Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Mul(args *Args, reply *Reply) error {
|
||||
reply.C = args.A * args.B
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) Div(args *Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Div(args *Args, reply *Reply) error {
|
||||
if args.B == 0 {
|
||||
return os.NewError("divide by zero")
|
||||
return errors.New("divide by zero")
|
||||
}
|
||||
reply.C = args.A / args.B
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) Error(args *Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Error(args *Args, reply *Reply) error {
|
||||
panic("ERROR")
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ func TestClient(t *testing.T) {
|
|||
reply := new(Reply)
|
||||
err := client.Call("Arith.Add", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", err.String())
|
||||
t.Errorf("Add: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
|
||||
|
@ -115,7 +115,7 @@ func TestClient(t *testing.T) {
|
|||
reply = new(Reply)
|
||||
err = client.Call("Arith.Mul", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Mul: expected no error but got string %q", err.String())
|
||||
t.Errorf("Mul: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A*args.B {
|
||||
t.Errorf("Mul: expected %d got %d", reply.C, args.A*args.B)
|
||||
|
@ -130,7 +130,7 @@ func TestClient(t *testing.T) {
|
|||
|
||||
addCall = <-addCall.Done
|
||||
if addCall.Error != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", addCall.Error.String())
|
||||
t.Errorf("Add: expected no error but got string %q", addCall.Error.Error())
|
||||
}
|
||||
if addReply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", addReply.C, args.A+args.B)
|
||||
|
@ -138,7 +138,7 @@ func TestClient(t *testing.T) {
|
|||
|
||||
mulCall = <-mulCall.Done
|
||||
if mulCall.Error != nil {
|
||||
t.Errorf("Mul: expected no error but got string %q", mulCall.Error.String())
|
||||
t.Errorf("Mul: expected no error but got string %q", mulCall.Error.Error())
|
||||
}
|
||||
if mulReply.C != args.A*args.B {
|
||||
t.Errorf("Mul: expected %d got %d", mulReply.C, args.A*args.B)
|
||||
|
@ -151,7 +151,7 @@ func TestClient(t *testing.T) {
|
|||
// expect an error: zero divide
|
||||
if err == nil {
|
||||
t.Error("Div: expected error")
|
||||
} else if err.String() != "divide by zero" {
|
||||
} else if err.Error() != "divide by zero" {
|
||||
t.Error("Div: expected divide by zero error; got", err)
|
||||
}
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ func TestMalformedInput(t *testing.T) {
|
|||
|
||||
func TestUnexpectedError(t *testing.T) {
|
||||
cli, srv := myPipe()
|
||||
go cli.PipeWriter.CloseWithError(os.NewError("unexpected error!")) // reader will get this error
|
||||
ServeConn(srv) // must return, not loop
|
||||
go cli.PipeWriter.CloseWithError(errors.New("unexpected error!")) // reader will get this error
|
||||
ServeConn(srv) // must return, not loop
|
||||
}
|
||||
|
||||
// Copied from package net.
|
||||
|
@ -191,7 +191,7 @@ func (pipeAddr) String() string {
|
|||
return "pipe"
|
||||
}
|
||||
|
||||
func (p *pipe) Close() os.Error {
|
||||
func (p *pipe) Close() error {
|
||||
err := p.PipeReader.Close()
|
||||
err1 := p.PipeWriter.Close()
|
||||
if err == nil {
|
||||
|
@ -208,14 +208,14 @@ func (p *pipe) RemoteAddr() net.Addr {
|
|||
return pipeAddr(0)
|
||||
}
|
||||
|
||||
func (p *pipe) SetTimeout(nsec int64) os.Error {
|
||||
return os.NewError("net.Pipe does not support timeouts")
|
||||
func (p *pipe) SetTimeout(nsec int64) error {
|
||||
return errors.New("net.Pipe does not support timeouts")
|
||||
}
|
||||
|
||||
func (p *pipe) SetReadTimeout(nsec int64) os.Error {
|
||||
return os.NewError("net.Pipe does not support timeouts")
|
||||
func (p *pipe) SetReadTimeout(nsec int64) error {
|
||||
return errors.New("net.Pipe does not support timeouts")
|
||||
}
|
||||
|
||||
func (p *pipe) SetWriteTimeout(nsec int64) os.Error {
|
||||
return os.NewError("net.Pipe does not support timeouts")
|
||||
func (p *pipe) SetWriteTimeout(nsec int64) error {
|
||||
return errors.New("net.Pipe does not support timeouts")
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"io"
|
||||
"json"
|
||||
"net"
|
||||
"os"
|
||||
"rpc"
|
||||
"sync"
|
||||
)
|
||||
|
@ -49,7 +48,7 @@ type clientRequest struct {
|
|||
Id uint64 `json:"id"`
|
||||
}
|
||||
|
||||
func (c *clientCodec) WriteRequest(r *rpc.Request, param interface{}) os.Error {
|
||||
func (c *clientCodec) WriteRequest(r *rpc.Request, param interface{}) error {
|
||||
c.mutex.Lock()
|
||||
c.pending[r.Seq] = r.ServiceMethod
|
||||
c.mutex.Unlock()
|
||||
|
@ -71,7 +70,7 @@ func (r *clientResponse) reset() {
|
|||
r.Error = nil
|
||||
}
|
||||
|
||||
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) os.Error {
|
||||
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
|
||||
c.resp.reset()
|
||||
if err := c.dec.Decode(&c.resp); err != nil {
|
||||
return err
|
||||
|
@ -97,14 +96,14 @@ func (c *clientCodec) ReadResponseHeader(r *rpc.Response) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *clientCodec) ReadResponseBody(x interface{}) os.Error {
|
||||
func (c *clientCodec) ReadResponseBody(x interface{}) error {
|
||||
if x == nil {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(*c.resp.Result, x)
|
||||
}
|
||||
|
||||
func (c *clientCodec) Close() os.Error {
|
||||
func (c *clientCodec) Close() error {
|
||||
return c.c.Close()
|
||||
}
|
||||
|
||||
|
@ -115,7 +114,7 @@ func NewClient(conn io.ReadWriteCloser) *rpc.Client {
|
|||
}
|
||||
|
||||
// Dial connects to a JSON-RPC server at the specified network address.
|
||||
func Dial(network, address string) (*rpc.Client, os.Error) {
|
||||
func Dial(network, address string) (*rpc.Client, error) {
|
||||
conn, err := net.Dial(network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
package jsonrpc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"json"
|
||||
"os"
|
||||
"rpc"
|
||||
"sync"
|
||||
)
|
||||
|
@ -64,7 +64,7 @@ type serverResponse struct {
|
|||
Error interface{} `json:"error"`
|
||||
}
|
||||
|
||||
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) os.Error {
|
||||
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
|
||||
c.req.reset()
|
||||
if err := c.dec.Decode(&c.req); err != nil {
|
||||
return err
|
||||
|
@ -84,7 +84,7 @@ func (c *serverCodec) ReadRequestHeader(r *rpc.Request) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *serverCodec) ReadRequestBody(x interface{}) os.Error {
|
||||
func (c *serverCodec) ReadRequestBody(x interface{}) error {
|
||||
if x == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -99,13 +99,13 @@ func (c *serverCodec) ReadRequestBody(x interface{}) os.Error {
|
|||
|
||||
var null = json.RawMessage([]byte("null"))
|
||||
|
||||
func (c *serverCodec) WriteResponse(r *rpc.Response, x interface{}) os.Error {
|
||||
func (c *serverCodec) WriteResponse(r *rpc.Response, x interface{}) error {
|
||||
var resp serverResponse
|
||||
c.mutex.Lock()
|
||||
b, ok := c.pending[r.Seq]
|
||||
if !ok {
|
||||
c.mutex.Unlock()
|
||||
return os.NewError("invalid sequence number in response")
|
||||
return errors.New("invalid sequence number in response")
|
||||
}
|
||||
delete(c.pending, r.Seq)
|
||||
c.mutex.Unlock()
|
||||
|
@ -124,7 +124,7 @@ func (c *serverCodec) WriteResponse(r *rpc.Response, x interface{}) os.Error {
|
|||
return c.enc.Encode(resp)
|
||||
}
|
||||
|
||||
func (c *serverCodec) Close() os.Error {
|
||||
func (c *serverCodec) Close() error {
|
||||
return c.c.Close()
|
||||
}
|
||||
|
||||
|
|
|
@ -114,12 +114,12 @@ package rpc
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"gob"
|
||||
"http"
|
||||
"log"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -135,7 +135,7 @@ const (
|
|||
|
||||
// Precompute the reflect type for os.Error. Can't use os.Error directly
|
||||
// because Typeof takes an empty interface value. This is annoying.
|
||||
var unusedError *os.Error
|
||||
var unusedError *error
|
||||
var typeOfOsError = reflect.TypeOf(unusedError).Elem()
|
||||
|
||||
type methodType struct {
|
||||
|
@ -215,17 +215,17 @@ func isExportedOrBuiltinType(t reflect.Type) bool {
|
|||
// suitable methods.
|
||||
// The client accesses each method using a string of the form "Type.Method",
|
||||
// where Type is the receiver's concrete type.
|
||||
func (server *Server) Register(rcvr interface{}) os.Error {
|
||||
func (server *Server) Register(rcvr interface{}) error {
|
||||
return server.register(rcvr, "", false)
|
||||
}
|
||||
|
||||
// RegisterName is like Register but uses the provided name for the type
|
||||
// instead of the receiver's concrete type.
|
||||
func (server *Server) RegisterName(name string, rcvr interface{}) os.Error {
|
||||
func (server *Server) RegisterName(name string, rcvr interface{}) error {
|
||||
return server.register(rcvr, name, true)
|
||||
}
|
||||
|
||||
func (server *Server) register(rcvr interface{}, name string, useName bool) os.Error {
|
||||
func (server *Server) register(rcvr interface{}, name string, useName bool) error {
|
||||
server.mu.Lock()
|
||||
defer server.mu.Unlock()
|
||||
if server.serviceMap == nil {
|
||||
|
@ -244,10 +244,10 @@ func (server *Server) register(rcvr interface{}, name string, useName bool) os.E
|
|||
if !isExported(sname) && !useName {
|
||||
s := "rpc Register: type " + sname + " is not exported"
|
||||
log.Print(s)
|
||||
return os.NewError(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
if _, present := server.serviceMap[sname]; present {
|
||||
return os.NewError("rpc: service already defined: " + sname)
|
||||
return errors.New("rpc: service already defined: " + sname)
|
||||
}
|
||||
s.name = sname
|
||||
s.method = make(map[string]*methodType)
|
||||
|
@ -296,7 +296,7 @@ func (server *Server) register(rcvr interface{}, name string, useName bool) os.E
|
|||
if len(s.method) == 0 {
|
||||
s := "rpc Register: type " + sname + " has no exported methods of suitable type"
|
||||
log.Print(s)
|
||||
return os.NewError(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
server.serviceMap[s.name] = s
|
||||
return nil
|
||||
|
@ -343,7 +343,7 @@ func (s *service) call(server *Server, sending *sync.Mutex, mtype *methodType, r
|
|||
errInter := returnValues[0].Interface()
|
||||
errmsg := ""
|
||||
if errInter != nil {
|
||||
errmsg = errInter.(os.Error).String()
|
||||
errmsg = errInter.(error).Error()
|
||||
}
|
||||
server.sendResponse(sending, req, replyv.Interface(), codec, errmsg)
|
||||
server.freeRequest(req)
|
||||
|
@ -356,15 +356,15 @@ type gobServerCodec struct {
|
|||
encBuf *bufio.Writer
|
||||
}
|
||||
|
||||
func (c *gobServerCodec) ReadRequestHeader(r *Request) os.Error {
|
||||
func (c *gobServerCodec) ReadRequestHeader(r *Request) error {
|
||||
return c.dec.Decode(r)
|
||||
}
|
||||
|
||||
func (c *gobServerCodec) ReadRequestBody(body interface{}) os.Error {
|
||||
func (c *gobServerCodec) ReadRequestBody(body interface{}) error {
|
||||
return c.dec.Decode(body)
|
||||
}
|
||||
|
||||
func (c *gobServerCodec) WriteResponse(r *Response, body interface{}) (err os.Error) {
|
||||
func (c *gobServerCodec) WriteResponse(r *Response, body interface{}) (err error) {
|
||||
if err = c.enc.Encode(r); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ func (c *gobServerCodec) WriteResponse(r *Response, body interface{}) (err os.Er
|
|||
return c.encBuf.Flush()
|
||||
}
|
||||
|
||||
func (c *gobServerCodec) Close() os.Error {
|
||||
func (c *gobServerCodec) Close() error {
|
||||
return c.rwc.Close()
|
||||
}
|
||||
|
||||
|
@ -396,7 +396,7 @@ func (server *Server) ServeCodec(codec ServerCodec) {
|
|||
for {
|
||||
service, mtype, req, argv, replyv, keepReading, err := server.readRequest(codec)
|
||||
if err != nil {
|
||||
if err != os.EOF {
|
||||
if err != io.EOF {
|
||||
log.Println("rpc:", err)
|
||||
}
|
||||
if !keepReading {
|
||||
|
@ -404,7 +404,7 @@ func (server *Server) ServeCodec(codec ServerCodec) {
|
|||
}
|
||||
// send a response if we actually managed to read a header.
|
||||
if req != nil {
|
||||
server.sendResponse(sending, req, invalidRequest, codec, err.String())
|
||||
server.sendResponse(sending, req, invalidRequest, codec, err.Error())
|
||||
server.freeRequest(req)
|
||||
}
|
||||
continue
|
||||
|
@ -416,7 +416,7 @@ func (server *Server) ServeCodec(codec ServerCodec) {
|
|||
|
||||
// ServeRequest is like ServeCodec but synchronously serves a single request.
|
||||
// It does not close the codec upon completion.
|
||||
func (server *Server) ServeRequest(codec ServerCodec) os.Error {
|
||||
func (server *Server) ServeRequest(codec ServerCodec) error {
|
||||
sending := new(sync.Mutex)
|
||||
service, mtype, req, argv, replyv, keepReading, err := server.readRequest(codec)
|
||||
if err != nil {
|
||||
|
@ -425,7 +425,7 @@ func (server *Server) ServeRequest(codec ServerCodec) os.Error {
|
|||
}
|
||||
// send a response if we actually managed to read a header.
|
||||
if req != nil {
|
||||
server.sendResponse(sending, req, invalidRequest, codec, err.String())
|
||||
server.sendResponse(sending, req, invalidRequest, codec, err.Error())
|
||||
server.freeRequest(req)
|
||||
}
|
||||
return err
|
||||
|
@ -474,7 +474,7 @@ func (server *Server) freeResponse(resp *Response) {
|
|||
server.respLock.Unlock()
|
||||
}
|
||||
|
||||
func (server *Server) readRequest(codec ServerCodec) (service *service, mtype *methodType, req *Request, argv, replyv reflect.Value, keepReading bool, err os.Error) {
|
||||
func (server *Server) readRequest(codec ServerCodec) (service *service, mtype *methodType, req *Request, argv, replyv reflect.Value, keepReading bool, err error) {
|
||||
service, mtype, req, keepReading, err = server.readRequestHeader(codec)
|
||||
if err != nil {
|
||||
if !keepReading {
|
||||
|
@ -505,16 +505,16 @@ func (server *Server) readRequest(codec ServerCodec) (service *service, mtype *m
|
|||
return
|
||||
}
|
||||
|
||||
func (server *Server) readRequestHeader(codec ServerCodec) (service *service, mtype *methodType, req *Request, keepReading bool, err os.Error) {
|
||||
func (server *Server) readRequestHeader(codec ServerCodec) (service *service, mtype *methodType, req *Request, keepReading bool, err error) {
|
||||
// Grab the request header.
|
||||
req = server.getRequest()
|
||||
err = codec.ReadRequestHeader(req)
|
||||
if err != nil {
|
||||
req = nil
|
||||
if err == os.EOF || err == io.ErrUnexpectedEOF {
|
||||
if err == io.EOF || err == io.ErrUnexpectedEOF {
|
||||
return
|
||||
}
|
||||
err = os.NewError("rpc: server cannot decode request: " + err.String())
|
||||
err = errors.New("rpc: server cannot decode request: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ func (server *Server) readRequestHeader(codec ServerCodec) (service *service, mt
|
|||
|
||||
serviceMethod := strings.Split(req.ServiceMethod, ".")
|
||||
if len(serviceMethod) != 2 {
|
||||
err = os.NewError("rpc: service/method request ill-formed: " + req.ServiceMethod)
|
||||
err = errors.New("rpc: service/method request ill-formed: " + req.ServiceMethod)
|
||||
return
|
||||
}
|
||||
// Look up the request.
|
||||
|
@ -532,12 +532,12 @@ func (server *Server) readRequestHeader(codec ServerCodec) (service *service, mt
|
|||
service = server.serviceMap[serviceMethod[0]]
|
||||
server.mu.Unlock()
|
||||
if service == nil {
|
||||
err = os.NewError("rpc: can't find service " + req.ServiceMethod)
|
||||
err = errors.New("rpc: can't find service " + req.ServiceMethod)
|
||||
return
|
||||
}
|
||||
mtype = service.method[serviceMethod[1]]
|
||||
if mtype == nil {
|
||||
err = os.NewError("rpc: can't find method " + req.ServiceMethod)
|
||||
err = errors.New("rpc: can't find method " + req.ServiceMethod)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -549,18 +549,18 @@ func (server *Server) Accept(lis net.Listener) {
|
|||
for {
|
||||
conn, err := lis.Accept()
|
||||
if err != nil {
|
||||
log.Fatal("rpc.Serve: accept:", err.String()) // TODO(r): exit?
|
||||
log.Fatal("rpc.Serve: accept:", err.Error()) // TODO(r): exit?
|
||||
}
|
||||
go server.ServeConn(conn)
|
||||
}
|
||||
}
|
||||
|
||||
// Register publishes the receiver's methods in the DefaultServer.
|
||||
func Register(rcvr interface{}) os.Error { return DefaultServer.Register(rcvr) }
|
||||
func Register(rcvr interface{}) error { return DefaultServer.Register(rcvr) }
|
||||
|
||||
// RegisterName is like Register but uses the provided name for the type
|
||||
// instead of the receiver's concrete type.
|
||||
func RegisterName(name string, rcvr interface{}) os.Error {
|
||||
func RegisterName(name string, rcvr interface{}) error {
|
||||
return DefaultServer.RegisterName(name, rcvr)
|
||||
}
|
||||
|
||||
|
@ -572,11 +572,11 @@ func RegisterName(name string, rcvr interface{}) os.Error {
|
|||
// connection. ReadRequestBody may be called with a nil
|
||||
// argument to force the body of the request to be read and discarded.
|
||||
type ServerCodec interface {
|
||||
ReadRequestHeader(*Request) os.Error
|
||||
ReadRequestBody(interface{}) os.Error
|
||||
WriteResponse(*Response, interface{}) os.Error
|
||||
ReadRequestHeader(*Request) error
|
||||
ReadRequestBody(interface{}) error
|
||||
WriteResponse(*Response, interface{}) error
|
||||
|
||||
Close() os.Error
|
||||
Close() error
|
||||
}
|
||||
|
||||
// ServeConn runs the DefaultServer on a single connection.
|
||||
|
@ -596,7 +596,7 @@ func ServeCodec(codec ServerCodec) {
|
|||
|
||||
// ServeRequest is like ServeCodec but synchronously serves a single request.
|
||||
// It does not close the codec upon completion.
|
||||
func ServeRequest(codec ServerCodec) os.Error {
|
||||
func ServeRequest(codec ServerCodec) error {
|
||||
return DefaultServer.ServeRequest(codec)
|
||||
}
|
||||
|
||||
|
@ -618,7 +618,7 @@ func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
conn, _, err := w.(http.Hijacker).Hijack()
|
||||
if err != nil {
|
||||
log.Print("rpc hijacking ", req.RemoteAddr, ": ", err.String())
|
||||
log.Print("rpc hijacking ", req.RemoteAddr, ": ", err.Error())
|
||||
return
|
||||
}
|
||||
io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n")
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"http/httptest"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -43,35 +43,35 @@ type Arith int
|
|||
|
||||
// Some of Arith's methods have value args, some have pointer args. That's deliberate.
|
||||
|
||||
func (t *Arith) Add(args Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Add(args Args, reply *Reply) error {
|
||||
reply.C = args.A + args.B
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) Mul(args *Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Mul(args *Args, reply *Reply) error {
|
||||
reply.C = args.A * args.B
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) Div(args Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Div(args Args, reply *Reply) error {
|
||||
if args.B == 0 {
|
||||
return os.NewError("divide by zero")
|
||||
return errors.New("divide by zero")
|
||||
}
|
||||
reply.C = args.A / args.B
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) String(args *Args, reply *string) os.Error {
|
||||
func (t *Arith) String(args *Args, reply *string) error {
|
||||
*reply = fmt.Sprintf("%d+%d=%d", args.A, args.B, args.A+args.B)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Arith) Scan(args string, reply *Reply) (err os.Error) {
|
||||
func (t *Arith) Scan(args string, reply *Reply) (err error) {
|
||||
_, err = fmt.Sscan(args, &reply.C)
|
||||
return
|
||||
}
|
||||
|
||||
func (t *Arith) Error(args *Args, reply *Reply) os.Error {
|
||||
func (t *Arith) Error(args *Args, reply *Reply) error {
|
||||
panic("ERROR")
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
reply := new(Reply)
|
||||
err = client.Call("Arith.Add", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", err.String())
|
||||
t.Errorf("Add: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
|
||||
|
@ -145,7 +145,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
// expect an error
|
||||
if err == nil {
|
||||
t.Error("BadOperation: expected error")
|
||||
} else if !strings.HasPrefix(err.String(), "rpc: can't find method ") {
|
||||
} else if !strings.HasPrefix(err.Error(), "rpc: can't find method ") {
|
||||
t.Errorf("BadOperation: expected can't find method error; got %q", err)
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
err = client.Call("Arith.Unknown", args, reply)
|
||||
if err == nil {
|
||||
t.Error("expected error calling unknown service")
|
||||
} else if strings.Index(err.String(), "method") < 0 {
|
||||
} else if strings.Index(err.Error(), "method") < 0 {
|
||||
t.Error("expected error about method; got", err)
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
|
||||
addCall = <-addCall.Done
|
||||
if addCall.Error != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", addCall.Error.String())
|
||||
t.Errorf("Add: expected no error but got string %q", addCall.Error.Error())
|
||||
}
|
||||
if addReply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", addReply.C, args.A+args.B)
|
||||
|
@ -176,7 +176,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
|
||||
mulCall = <-mulCall.Done
|
||||
if mulCall.Error != nil {
|
||||
t.Errorf("Mul: expected no error but got string %q", mulCall.Error.String())
|
||||
t.Errorf("Mul: expected no error but got string %q", mulCall.Error.Error())
|
||||
}
|
||||
if mulReply.C != args.A*args.B {
|
||||
t.Errorf("Mul: expected %d got %d", mulReply.C, args.A*args.B)
|
||||
|
@ -189,7 +189,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
// expect an error: zero divide
|
||||
if err == nil {
|
||||
t.Error("Div: expected error")
|
||||
} else if err.String() != "divide by zero" {
|
||||
} else if err.Error() != "divide by zero" {
|
||||
t.Error("Div: expected divide by zero error; got", err)
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
err = client.Call("Arith.Add", reply, reply) // args, reply would be the correct thing to use
|
||||
if err == nil {
|
||||
t.Error("expected error calling Arith.Add with wrong arg type")
|
||||
} else if strings.Index(err.String(), "type") < 0 {
|
||||
} else if strings.Index(err.Error(), "type") < 0 {
|
||||
t.Error("expected error about type; got", err)
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
reply = new(Reply)
|
||||
err = client.Call("Arith.Scan", &str, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Scan: expected no error but got string %q", err.String())
|
||||
t.Errorf("Scan: expected no error but got string %q", err.Error())
|
||||
} else if reply.C != Val {
|
||||
t.Errorf("Scan: expected %d got %d", Val, reply.C)
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
str = ""
|
||||
err = client.Call("Arith.String", args, &str)
|
||||
if err != nil {
|
||||
t.Errorf("String: expected no error but got string %q", err.String())
|
||||
t.Errorf("String: expected no error but got string %q", err.Error())
|
||||
}
|
||||
expect := fmt.Sprintf("%d+%d=%d", args.A, args.B, args.A+args.B)
|
||||
if str != expect {
|
||||
|
@ -229,7 +229,7 @@ func testRPC(t *testing.T, addr string) {
|
|||
reply = new(Reply)
|
||||
err = client.Call("Arith.Mul", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Mul: expected no error but got string %q", err.String())
|
||||
t.Errorf("Mul: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A*args.B {
|
||||
t.Errorf("Mul: expected %d got %d", reply.C, args.A*args.B)
|
||||
|
@ -245,7 +245,7 @@ func TestHTTP(t *testing.T) {
|
|||
|
||||
func testHTTPRPC(t *testing.T, path string) {
|
||||
var client *Client
|
||||
var err os.Error
|
||||
var err error
|
||||
if path == "" {
|
||||
client, err = DialHTTP("tcp", httpServerAddr)
|
||||
} else {
|
||||
|
@ -260,7 +260,7 @@ func testHTTPRPC(t *testing.T, path string) {
|
|||
reply := new(Reply)
|
||||
err = client.Call("Arith.Add", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", err.String())
|
||||
t.Errorf("Add: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
|
||||
|
@ -274,15 +274,15 @@ type CodecEmulator struct {
|
|||
serviceMethod string
|
||||
args *Args
|
||||
reply *Reply
|
||||
err os.Error
|
||||
err error
|
||||
}
|
||||
|
||||
func (codec *CodecEmulator) Call(serviceMethod string, args *Args, reply *Reply) os.Error {
|
||||
func (codec *CodecEmulator) Call(serviceMethod string, args *Args, reply *Reply) error {
|
||||
codec.serviceMethod = serviceMethod
|
||||
codec.args = args
|
||||
codec.reply = reply
|
||||
codec.err = nil
|
||||
var serverError os.Error
|
||||
var serverError error
|
||||
if codec.server == nil {
|
||||
serverError = ServeRequest(codec)
|
||||
} else {
|
||||
|
@ -294,13 +294,13 @@ func (codec *CodecEmulator) Call(serviceMethod string, args *Args, reply *Reply)
|
|||
return codec.err
|
||||
}
|
||||
|
||||
func (codec *CodecEmulator) ReadRequestHeader(req *Request) os.Error {
|
||||
func (codec *CodecEmulator) ReadRequestHeader(req *Request) error {
|
||||
req.ServiceMethod = codec.serviceMethod
|
||||
req.Seq = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
func (codec *CodecEmulator) ReadRequestBody(argv interface{}) os.Error {
|
||||
func (codec *CodecEmulator) ReadRequestBody(argv interface{}) error {
|
||||
if codec.args == nil {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
|
@ -308,16 +308,16 @@ func (codec *CodecEmulator) ReadRequestBody(argv interface{}) os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (codec *CodecEmulator) WriteResponse(resp *Response, reply interface{}) os.Error {
|
||||
func (codec *CodecEmulator) WriteResponse(resp *Response, reply interface{}) error {
|
||||
if resp.Error != "" {
|
||||
codec.err = os.NewError(resp.Error)
|
||||
codec.err = errors.New(resp.Error)
|
||||
} else {
|
||||
*codec.reply = *(reply.(*Reply))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (codec *CodecEmulator) Close() os.Error {
|
||||
func (codec *CodecEmulator) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ func testServeRequest(t *testing.T, server *Server) {
|
|||
reply := new(Reply)
|
||||
err := client.Call("Arith.Add", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", err.String())
|
||||
t.Errorf("Add: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
|
||||
|
@ -352,15 +352,15 @@ type ArgNotPublic int
|
|||
type ReplyNotPublic int
|
||||
type local struct{}
|
||||
|
||||
func (t *ReplyNotPointer) ReplyNotPointer(args *Args, reply Reply) os.Error {
|
||||
func (t *ReplyNotPointer) ReplyNotPointer(args *Args, reply Reply) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ArgNotPublic) ArgNotPublic(args *local, reply *Reply) os.Error {
|
||||
func (t *ArgNotPublic) ArgNotPublic(args *local, reply *Reply) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ReplyNotPublic) ReplyNotPublic(args *Args, reply *local) os.Error {
|
||||
func (t *ReplyNotPublic) ReplyNotPublic(args *Args, reply *local) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -382,22 +382,22 @@ func TestRegistrationError(t *testing.T) {
|
|||
|
||||
type WriteFailCodec int
|
||||
|
||||
func (WriteFailCodec) WriteRequest(*Request, interface{}) os.Error {
|
||||
func (WriteFailCodec) WriteRequest(*Request, interface{}) error {
|
||||
// the panic caused by this error used to not unlock a lock.
|
||||
return os.NewError("fail")
|
||||
return errors.New("fail")
|
||||
}
|
||||
|
||||
func (WriteFailCodec) ReadResponseHeader(*Response) os.Error {
|
||||
func (WriteFailCodec) ReadResponseHeader(*Response) error {
|
||||
time.Sleep(120e9)
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (WriteFailCodec) ReadResponseBody(interface{}) os.Error {
|
||||
func (WriteFailCodec) ReadResponseBody(interface{}) error {
|
||||
time.Sleep(120e9)
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (WriteFailCodec) Close() os.Error {
|
||||
func (WriteFailCodec) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -427,15 +427,15 @@ func testSendDeadlock(client *Client) {
|
|||
client.Call("Arith.Add", args, reply)
|
||||
}
|
||||
|
||||
func dialDirect() (*Client, os.Error) {
|
||||
func dialDirect() (*Client, error) {
|
||||
return Dial("tcp", serverAddr)
|
||||
}
|
||||
|
||||
func dialHTTP() (*Client, os.Error) {
|
||||
func dialHTTP() (*Client, error) {
|
||||
return DialHTTP("tcp", httpServerAddr)
|
||||
}
|
||||
|
||||
func countMallocs(dial func() (*Client, os.Error), t *testing.T) uint64 {
|
||||
func countMallocs(dial func() (*Client, error), t *testing.T) uint64 {
|
||||
once.Do(startServer)
|
||||
client, err := dial()
|
||||
if err != nil {
|
||||
|
@ -449,7 +449,7 @@ func countMallocs(dial func() (*Client, os.Error), t *testing.T) uint64 {
|
|||
for i := 0; i < count; i++ {
|
||||
err := client.Call("Arith.Add", args, reply)
|
||||
if err != nil {
|
||||
t.Errorf("Add: expected no error but got string %q", err.String())
|
||||
t.Errorf("Add: expected no error but got string %q", err.Error())
|
||||
}
|
||||
if reply.C != args.A+args.B {
|
||||
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
|
||||
|
@ -470,16 +470,16 @@ func TestCountMallocsOverHTTP(t *testing.T) {
|
|||
|
||||
type writeCrasher struct{}
|
||||
|
||||
func (writeCrasher) Close() os.Error {
|
||||
func (writeCrasher) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (writeCrasher) Read(p []byte) (int, os.Error) {
|
||||
return 0, os.EOF
|
||||
func (writeCrasher) Read(p []byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (writeCrasher) Write(p []byte) (int, os.Error) {
|
||||
return 0, os.NewError("fake write failure")
|
||||
func (writeCrasher) Write(p []byte) (int, error) {
|
||||
return 0, errors.New("fake write failure")
|
||||
}
|
||||
|
||||
func TestClientWriteError(t *testing.T) {
|
||||
|
@ -489,12 +489,12 @@ func TestClientWriteError(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
if err.String() != "fake write failure" {
|
||||
if err.Error() != "fake write failure" {
|
||||
t.Error("unexpected value of error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkEndToEnd(dial func() (*Client, os.Error), b *testing.B) {
|
||||
func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
|
||||
b.StopTimer()
|
||||
once.Do(startServer)
|
||||
client, err := dial()
|
||||
|
@ -517,7 +517,7 @@ func benchmarkEndToEnd(dial func() (*Client, os.Error), b *testing.B) {
|
|||
for atomic.AddInt32(&N, -1) >= 0 {
|
||||
err = client.Call("Arith.Add", args, reply)
|
||||
if err != nil {
|
||||
fmt.Printf("Add: expected no error but got string %q", err.String())
|
||||
fmt.Printf("Add: expected no error but got string %q", err.Error())
|
||||
panic("rpc error")
|
||||
}
|
||||
if reply.C != args.A+args.B {
|
||||
|
@ -531,7 +531,7 @@ func benchmarkEndToEnd(dial func() (*Client, os.Error), b *testing.B) {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
func benchmarkEndToEndAsync(dial func() (*Client, os.Error), b *testing.B) {
|
||||
func benchmarkEndToEndAsync(dial func() (*Client, error), b *testing.B) {
|
||||
const MaxConcurrentCalls = 100
|
||||
b.StopTimer()
|
||||
once.Do(startServer)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue