Created
April 23, 2011 17:05
-
-
Save taruti/938779 to your computer and use it in GitHub Desktop.
tcp client net for plan9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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