add network listening & tests
R=r,presotto
OCL=15410
CL=15440
diff --git a/src/lib/io.go b/src/lib/io.go
index d7770eb..266d948 100644
--- a/src/lib/io.go
+++ b/src/lib/io.go
@@ -4,17 +4,7 @@
package io
import os "os"
-
-export func StringToBytes(b *[]byte, s string) bool {
- if len(s) >= len(b) {
- return false
- }
- for i := 0; i < len(s); i++ {
- b[i] = s[i]
- }
- b[len(s)] = '\000'; // not necessary - memory is zeroed - but be explicit
- return true
-}
+import syscall "syscall"
export type Read interface {
Read(p *[]byte) (n int, err *os.Error);
@@ -24,13 +14,17 @@
Write(p *[]byte) (n int, err *os.Error);
}
+export type ReadWrite interface {
+ Read(p *[]byte) (n int, err *os.Error);
+ Write(p *[]byte) (n int, err *os.Error);
+}
+
export func WriteString(w Write, s string) (n int, err *os.Error) {
b := new([]byte, len(s)+1)
- if !StringToBytes(b, s) {
+ if !syscall.StringToBytes(b, s) {
return -1, os.EINVAL
}
// BUG return w.Write(b[0:len(s)])
r, e := w.Write(b[0:len(s)])
return r, e
}
-