aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/net/ipsock_plan9.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/ipsock_plan9.go')
-rw-r--r--libgo/go/net/ipsock_plan9.go62
1 files changed, 40 insertions, 22 deletions
diff --git a/libgo/go/net/ipsock_plan9.go b/libgo/go/net/ipsock_plan9.go
index eaef768..c7d542d 100644
--- a/libgo/go/net/ipsock_plan9.go
+++ b/libgo/go/net/ipsock_plan9.go
@@ -9,6 +9,7 @@ package net
import (
"errors"
"os"
+ "syscall"
)
// /sys/include/ape/sys/socket.h:/SOMAXCONN
@@ -104,72 +105,89 @@ 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) (*netFD, error) {
+func netErr(e error) {
+ oe, ok := e.(*OpError)
+ if !ok {
+ return
+ }
+ if pe, ok := oe.Err.(*os.PathError); ok {
+ if _, ok = pe.Err.(syscall.ErrorString); ok {
+ oe.Err = pe.Err
+ }
+ }
+}
+
+func dialPlan9(net string, laddr, raddr Addr) (fd *netFD, err error) {
+ defer func() { netErr(err) }()
f, dest, proto, name, err := startPlan9(net, raddr)
if err != nil {
- return nil, err
+ return nil, &OpError{"dial", net, raddr, err}
}
_, err = f.WriteString("connect " + dest)
if err != nil {
f.Close()
- return nil, err
+ return nil, &OpError{"dial", f.Name(), raddr, err}
}
- laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
+ data, err := os.OpenFile("/net/"+proto+"/"+name+"/data", os.O_RDWR, 0)
if err != nil {
f.Close()
- return nil, err
+ return nil, &OpError{"dial", net, raddr, err}
}
- raddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/remote")
+ laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
if err != nil {
+ data.Close()
f.Close()
- return nil, err
+ return nil, &OpError{"dial", proto, raddr, err}
}
- return newFD(proto, name, f, laddr, raddr), nil
+ return newFD(proto, name, f, data, laddr, raddr), nil
}
-func listenPlan9(net string, laddr Addr) (*netFD, error) {
+func listenPlan9(net string, laddr Addr) (fd *netFD, err error) {
+ defer func() { netErr(err) }()
f, dest, proto, name, err := startPlan9(net, laddr)
if err != nil {
- return nil, err
+ return nil, &OpError{"listen", net, laddr, err}
}
_, err = f.WriteString("announce " + dest)
if err != nil {
f.Close()
- return nil, err
+ return nil, &OpError{"announce", proto, laddr, err}
}
laddr, err = readPlan9Addr(proto, "/net/"+proto+"/"+name+"/local")
if err != nil {
f.Close()
- return nil, err
+ return nil, &OpError{Op: "listen", Net: net, Err: err}
}
- return &netFD{proto: proto, name: name, dir: "/net/" + proto + "/" + name, ctl: f, laddr: laddr}, nil
+ return newFD(proto, name, f, nil, laddr, nil), nil
}
func (l *netFD) netFD() *netFD {
- return newFD(l.proto, l.name, l.ctl, l.laddr, nil)
+ return newFD(l.proto, l.name, l.ctl, l.data, l.laddr, l.raddr)
}
-func (l *netFD) acceptPlan9() (*netFD, error) {
+func (l *netFD) acceptPlan9() (fd *netFD, err error) {
+ defer func() { netErr(err) }()
f, err := os.Open(l.dir + "/listen")
if err != nil {
- return nil, err
+ return nil, &OpError{"accept", l.dir + "/listen", l.laddr, err}
}
var buf [16]byte
n, err := f.Read(buf[:])
if err != nil {
f.Close()
- return nil, err
+ return nil, &OpError{"accept", l.dir + "/listen", l.laddr, err}
}
name := string(buf[:n])
- laddr, err := readPlan9Addr(l.proto, l.dir+"/local")
+ data, err := os.OpenFile("/net/"+l.proto+"/"+name+"/data", os.O_RDWR, 0)
if err != nil {
f.Close()
- return nil, err
+ return nil, &OpError{"accept", l.proto, l.laddr, err}
}
- raddr, err := readPlan9Addr(l.proto, l.dir+"/remote")
+ raddr, err := readPlan9Addr(l.proto, "/net/"+l.proto+"/"+name+"/remote")
if err != nil {
+ data.Close()
f.Close()
- return nil, err
+ return nil, &OpError{"accept", l.proto, l.laddr, err}
}
- return newFD(l.proto, name, f, laddr, raddr), nil
+ return newFD(l.proto, name, f, data, l.laddr, raddr), nil
}