2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
2011-08-17 11:28:29 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
net, cmd/fix: add IPv6 scoped addressing zone to INET, INET6 address structs
This CL starts to introduce IPv6 scoped addressing capability
into the net package.
The Public API changes are:
+pkg net, type IPAddr struct, Zone string
+pkg net, type IPNet struct, Zone string
+pkg net, type TCPAddr struct, Zone string
+pkg net, type UDPAddr struct, Zone string
Update #4234.
R=rsc, bradfitz, iant
CC=golang-dev
https://golang.org/cl/6849045
2012-11-26 08:45:42 -07:00
|
|
|
// Internet protocol family sockets for Plan 9
|
2011-08-17 11:28:29 -06:00
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
"context"
|
2011-08-17 11:28:29 -06:00
|
|
|
"os"
|
net, os, syscall: Plan 9: adjust error handling
syscall: Use NewError for all system errors and introduce
some new errors for compatibility with other packages
and proper error handling in net. Also introduce
Temporary and Timeout methods on ErrorString.
net: Make errors from dial, accept, listen functions follow the
OpError standard and discern whether the underlying
error came from syscall. Since Plan 9 uses a correspondence
between file and network operations, all system error
reporting happens through the underlying file operation.
In Go code, we go through package os for file operations,
so there is another level of indirection in error types.
This change allows us to compare the errors with those in
package syscall, when appropriate.
os: Just use the error string already present in package os,
instead of calling out to package syscall.
R=rsc, ality, rminnich, bradfitz
CC=golang-dev
https://golang.org/cl/7398054
2013-02-27 22:43:21 -07:00
|
|
|
"syscall"
|
2011-08-17 11:28:29 -06:00
|
|
|
)
|
|
|
|
|
2014-01-29 17:49:32 -07:00
|
|
|
func probe(filename, query string) bool {
|
2014-01-22 14:21:53 -07:00
|
|
|
var file *file
|
|
|
|
var err error
|
|
|
|
if file, err = open(filename); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
r := false
|
|
|
|
for line, ok := file.readLine(); ok && !r; line, ok = file.readLine() {
|
|
|
|
f := getFields(line)
|
|
|
|
if len(f) < 3 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for i := 0; i < len(f); i++ {
|
|
|
|
if query == f[i] {
|
|
|
|
r = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close()
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2013-08-02 21:17:01 -06:00
|
|
|
func probeIPv4Stack() bool {
|
2014-01-29 17:49:32 -07:00
|
|
|
return probe(netdir+"/iproute", "4i")
|
2013-08-02 21:17:01 -06:00
|
|
|
}
|
|
|
|
|
2016-03-01 16:21:55 -07:00
|
|
|
// probeIPv6Stack returns two boolean values. If the first boolean
|
|
|
|
// value is true, kernel supports basic IPv6 functionality. If the
|
2012-09-26 01:11:49 -06:00
|
|
|
// second boolean value is true, kernel supports IPv6 IPv4-mapping.
|
2011-08-17 11:28:29 -06:00
|
|
|
func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
|
2014-01-22 14:21:53 -07:00
|
|
|
// Plan 9 uses IPv6 natively, see ip(3).
|
2014-01-29 17:49:32 -07:00
|
|
|
r := probe(netdir+"/iproute", "6i")
|
2014-01-22 14:21:53 -07:00
|
|
|
v := false
|
|
|
|
if r {
|
2014-01-29 17:49:32 -07:00
|
|
|
v = probe(netdir+"/iproute", "4i")
|
2014-01-22 14:21:53 -07:00
|
|
|
}
|
|
|
|
return r, v
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// parsePlan9Addr parses address of the form [ip!]port (e.g. 127.0.0.1!80).
|
2011-11-01 20:05:34 -06:00
|
|
|
func parsePlan9Addr(s string) (ip IP, iport int, err error) {
|
2012-01-31 08:36:45 -07:00
|
|
|
addr := IPv4zero // address contains port only
|
2012-02-05 17:59:32 -07:00
|
|
|
i := byteIndex(s, '!')
|
2011-08-17 11:28:29 -06:00
|
|
|
if i >= 0 {
|
|
|
|
addr = ParseIP(s[:i])
|
|
|
|
if addr == nil {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, 0, &ParseError{Type: "IP address", Text: s}
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-31 08:36:45 -07:00
|
|
|
p, _, ok := dtoi(s[i+1:], 0)
|
2011-08-17 11:28:29 -06:00
|
|
|
if !ok {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, 0, &ParseError{Type: "port", Text: s}
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
if p < 0 || p > 0xFFFF {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, 0, &AddrError{Err: "invalid port", Addr: string(p)}
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
return addr, p, nil
|
|
|
|
}
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func readPlan9Addr(proto, filename string) (addr Addr, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
var buf [128]byte
|
|
|
|
|
|
|
|
f, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2012-06-06 16:38:56 -06:00
|
|
|
defer f.Close()
|
2011-08-17 11:28:29 -06:00
|
|
|
n, err := f.Read(buf[:])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ip, port, err := parsePlan9Addr(string(buf[:n]))
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch proto {
|
|
|
|
case "tcp":
|
net, cmd/fix: add IPv6 scoped addressing zone to INET, INET6 address structs
This CL starts to introduce IPv6 scoped addressing capability
into the net package.
The Public API changes are:
+pkg net, type IPAddr struct, Zone string
+pkg net, type IPNet struct, Zone string
+pkg net, type TCPAddr struct, Zone string
+pkg net, type UDPAddr struct, Zone string
Update #4234.
R=rsc, bradfitz, iant
CC=golang-dev
https://golang.org/cl/6849045
2012-11-26 08:45:42 -07:00
|
|
|
addr = &TCPAddr{IP: ip, Port: port}
|
2011-08-17 11:28:29 -06:00
|
|
|
case "udp":
|
net, cmd/fix: add IPv6 scoped addressing zone to INET, INET6 address structs
This CL starts to introduce IPv6 scoped addressing capability
into the net package.
The Public API changes are:
+pkg net, type IPAddr struct, Zone string
+pkg net, type IPNet struct, Zone string
+pkg net, type TCPAddr struct, Zone string
+pkg net, type UDPAddr struct, Zone string
Update #4234.
R=rsc, bradfitz, iant
CC=golang-dev
https://golang.org/cl/6849045
2012-11-26 08:45:42 -07:00
|
|
|
addr = &UDPAddr{IP: ip, Port: port}
|
2011-08-17 11:28:29 -06:00
|
|
|
default:
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return nil, UnknownNetworkError(proto)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
func startPlan9(ctx context.Context, net string, addr Addr) (ctl *os.File, dest, proto, name string, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
var (
|
|
|
|
ip IP
|
|
|
|
port int
|
|
|
|
)
|
|
|
|
switch a := addr.(type) {
|
|
|
|
case *TCPAddr:
|
|
|
|
proto = "tcp"
|
|
|
|
ip = a.IP
|
|
|
|
port = a.Port
|
|
|
|
case *UDPAddr:
|
|
|
|
proto = "udp"
|
|
|
|
ip = a.IP
|
|
|
|
port = a.Port
|
|
|
|
default:
|
|
|
|
err = UnknownNetworkError(net)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
clone, dest, err := queryCS1(ctx, proto, ip, port)
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f, err := os.OpenFile(clone, os.O_RDWR, 0)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var buf [16]byte
|
|
|
|
n, err := f.Read(buf[:])
|
|
|
|
if err != nil {
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2011-08-17 11:28:29 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
return f, dest, proto, string(buf[:n]), nil
|
|
|
|
}
|
|
|
|
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
func fixErr(err error) {
|
|
|
|
oe, ok := err.(*OpError)
|
net, os, syscall: Plan 9: adjust error handling
syscall: Use NewError for all system errors and introduce
some new errors for compatibility with other packages
and proper error handling in net. Also introduce
Temporary and Timeout methods on ErrorString.
net: Make errors from dial, accept, listen functions follow the
OpError standard and discern whether the underlying
error came from syscall. Since Plan 9 uses a correspondence
between file and network operations, all system error
reporting happens through the underlying file operation.
In Go code, we go through package os for file operations,
so there is another level of indirection in error types.
This change allows us to compare the errors with those in
package syscall, when appropriate.
os: Just use the error string already present in package os,
instead of calling out to package syscall.
R=rsc, ality, rminnich, bradfitz
CC=golang-dev
https://golang.org/cl/7398054
2013-02-27 22:43:21 -07:00
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2015-05-29 16:33:16 -06:00
|
|
|
nonNilInterface := func(a Addr) bool {
|
|
|
|
switch a := a.(type) {
|
|
|
|
case *TCPAddr:
|
|
|
|
return a == nil
|
|
|
|
case *UDPAddr:
|
|
|
|
return a == nil
|
|
|
|
case *IPAddr:
|
|
|
|
return a == nil
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if nonNilInterface(oe.Source) {
|
|
|
|
oe.Source = nil
|
|
|
|
}
|
|
|
|
if nonNilInterface(oe.Addr) {
|
|
|
|
oe.Addr = nil
|
|
|
|
}
|
net, os, syscall: Plan 9: adjust error handling
syscall: Use NewError for all system errors and introduce
some new errors for compatibility with other packages
and proper error handling in net. Also introduce
Temporary and Timeout methods on ErrorString.
net: Make errors from dial, accept, listen functions follow the
OpError standard and discern whether the underlying
error came from syscall. Since Plan 9 uses a correspondence
between file and network operations, all system error
reporting happens through the underlying file operation.
In Go code, we go through package os for file operations,
so there is another level of indirection in error types.
This change allows us to compare the errors with those in
package syscall, when appropriate.
os: Just use the error string already present in package os,
instead of calling out to package syscall.
R=rsc, ality, rminnich, bradfitz
CC=golang-dev
https://golang.org/cl/7398054
2013-02-27 22:43:21 -07:00
|
|
|
if pe, ok := oe.Err.(*os.PathError); ok {
|
|
|
|
if _, ok = pe.Err.(syscall.ErrorString); ok {
|
|
|
|
oe.Err = pe.Err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
func dialPlan9(ctx context.Context, net string, laddr, raddr Addr) (fd *netFD, err error) {
|
|
|
|
defer func() { fixErr(err) }()
|
|
|
|
type res struct {
|
|
|
|
fd *netFD
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
resc := make(chan res)
|
|
|
|
go func() {
|
|
|
|
testHookDialChannel()
|
|
|
|
fd, err := dialPlan9Blocking(ctx, net, laddr, raddr)
|
|
|
|
select {
|
|
|
|
case resc <- res{fd, err}:
|
|
|
|
case <-ctx.Done():
|
|
|
|
if fd != nil {
|
|
|
|
fd.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case res := <-resc:
|
|
|
|
return res.fd, res.err
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, mapErr(ctx.Err())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func dialPlan9Blocking(ctx context.Context, net string, laddr, raddr Addr) (fd *netFD, err error) {
|
|
|
|
f, dest, proto, name, err := startPlan9(ctx, net, raddr)
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
_, err = f.WriteString("connect " + dest)
|
|
|
|
if err != nil {
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2014-01-22 14:21:53 -07:00
|
|
|
data, err := os.OpenFile(netdir+"/"+proto+"/"+name+"/data", os.O_RDWR, 0)
|
2013-02-19 18:11:17 -07:00
|
|
|
if err != nil {
|
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2013-02-19 18:11:17 -07:00
|
|
|
}
|
2014-01-22 14:21:53 -07:00
|
|
|
laddr, err = readPlan9Addr(proto, netdir+"/"+proto+"/"+name+"/local")
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2013-02-19 18:11:17 -07:00
|
|
|
data.Close()
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2014-01-22 14:21:53 -07:00
|
|
|
return newFD(proto, name, f, data, laddr, raddr)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
func listenPlan9(ctx context.Context, net string, laddr Addr) (fd *netFD, err error) {
|
|
|
|
defer func() { fixErr(err) }()
|
|
|
|
f, dest, proto, name, err := startPlan9(ctx, net, laddr)
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
_, err = f.WriteString("announce " + dest)
|
|
|
|
if err != nil {
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2014-01-22 14:21:53 -07:00
|
|
|
laddr, err = readPlan9Addr(proto, netdir+"/"+proto+"/"+name+"/local")
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2014-01-22 14:21:53 -07:00
|
|
|
return newFD(proto, name, f, nil, laddr, nil)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2015-04-21 07:53:47 -06:00
|
|
|
func (fd *netFD) netFD() (*netFD, error) {
|
|
|
|
return newFD(fd.net, fd.n, fd.ctl, fd.data, fd.laddr, fd.raddr)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2015-04-21 07:53:47 -06:00
|
|
|
func (fd *netFD) acceptPlan9() (nfd *netFD, err error) {
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
defer func() { fixErr(err) }()
|
2015-04-21 07:53:47 -06:00
|
|
|
if err := fd.readLock(); err != nil {
|
2014-01-22 14:21:53 -07:00
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-21 07:53:47 -06:00
|
|
|
defer fd.readUnlock()
|
|
|
|
f, err := os.Open(fd.dir + "/listen")
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
var buf [16]byte
|
|
|
|
n, err := f.Read(buf[:])
|
|
|
|
if err != nil {
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
name := string(buf[:n])
|
2015-04-21 07:53:47 -06:00
|
|
|
data, err := os.OpenFile(netdir+"/"+fd.net+"/"+name+"/data", os.O_RDWR, 0)
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2015-04-21 07:53:47 -06:00
|
|
|
raddr, err := readPlan9Addr(fd.net, netdir+"/"+fd.net+"/"+name+"/remote")
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
2013-02-19 18:11:17 -07:00
|
|
|
data.Close()
|
2012-06-06 16:38:56 -06:00
|
|
|
f.Close()
|
2016-03-02 04:08:18 -07:00
|
|
|
return nil, err
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
2015-04-21 07:53:47 -06:00
|
|
|
return newFD(fd.net, name, f, data, fd.laddr, raddr)
|
2012-09-26 01:11:49 -06:00
|
|
|
}
|