Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

tcp client net for plan9

View gist:938779
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff -r 35d6bf757194 src/pkg/net/Makefile
--- a/src/pkg/net/Makefile Sat Apr 23 16:04:57 2011 +0300
+++ b/src/pkg/net/Makefile Sat Apr 23 16:21:48 2011 +0300
@@ -38,7 +38,7 @@
dnsconfig.go\
dnsclient.go\
port.go\
-
+
GOFILES_linux=\
newpollserver.go\
fd.go\
@@ -53,4 +53,11 @@
GOFILES+=$(GOFILES_$(GOOS))
+ifeq ($(GOOS),plan9)
+GOFILES=\
+ net.go\
+ net_plan9.go\
+
+endif
+
include ../../Make.pkg
diff -r 35d6bf757194 src/pkg/net/net_plan9.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pkg/net/net_plan9.go Sat Apr 23 16:21:48 2011 +0300
@@ -0,0 +1,57 @@
+package net
+
+import "os"
+import "strings"
+
+func Dial(proto, raddr string) (Conn, os.Error) {
+ cs,err := resolve("/net", proto, raddr)
+ if err!=nil || len(cs)==0 { return nil,err }
+ ca,err := connect(cs[0])
+ return TCP{ca}, err
+}
+
+func Listen(net, laddr string) (l Listener, err os.Error) {
+ return nil, os.EPLAN9
+}
+
+type TCP struct { *os.File }
+
+
+func resolve(net string, proto string, addr string) ([]string, os.Error) {
+ var buf [4096]byte
+
+ i := strings.LastIndex(addr, ":")
+ a := []byte(proto+"!"+addr)
+ if i > 0 {
+ a[i+len(proto)+1] = '!'
+ }
+
+ f,err := os.OpenFile(net+"/cs", os.O_RDWR, 0)
+ if err!=nil { return nil,err }
+ _,err = f.Write(a)
+ if err!=nil { return nil,err}
+ f.Seek(0,0)
+ n,err := f.Read(buf[:])
+ if err!=nil { return nil,err }
+ return strings.Split(string(buf[:n]), "\n", -1), nil
+}
+
+func connect(csa string) (*os.File,os.Error) {
+ var buf [16]byte
+ ca := strings.Split(csa, " ", 2)
+ f,err := os.OpenFile(ca[0], os.O_RDWR, 0)
+ defer f.Close()
+ if err!=nil { return nil,err }
+ n,err := f.Read(buf[:])
+ if err!=nil { return nil,err }
+ _,err = f.Write([]byte("connect "+ca[1]))
+ if err!=nil { return nil,err }
+ d,err := os.OpenFile(ca[0][:len(ca[0])-5]+string(buf[0:n])+"/data", os.O_RDWR, 0)
+ return d,err
+}
+
+func (TCP)LocalAddr() Addr { return nil }
+func (TCP)RemoteAddr() Addr { return nil }
+func (TCP)SetTimeout(nsec int64) os.Error { return os.EPLAN9 }
+func (TCP)SetReadTimeout(nsec int64) os.Error { return os.EPLAN9 }
+func (TCP)SetWriteTimeout(nsec int64) os.Error { return os.EPLAN9 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.