tcp clients now get per-client consistency

all root-level s-expressions are evaluated in-order, on a per-client
basis.
master
Jordan Orelli 12 years ago
parent 9a55b787a0
commit cf73b5fec0

@ -29,6 +29,7 @@ func (m *Manager) run() {
case conn := <-m.connect: case conn := <-m.connect:
m.active[conn] = true m.active[conn] = true
case conn := <-m.disconnect: case conn := <-m.disconnect:
conn.Close()
delete(m.active, conn) delete(m.active, conn)
case op := <-m.write: case op := <-m.write:
m.broadcast(op) m.broadcast(op)

@ -140,7 +140,6 @@ func (s *sexp) readIn(c chan token) error {
s.append(v) s.append(v)
} }
} }
fmt.Println("sexp.readIn hit weird EOF")
return errors.New("unexpected EOF in sexp.readIn") return errors.New("unexpected EOF in sexp.readIn")
} }

@ -23,6 +23,8 @@ func depth(s string) int {
n += 1 n += 1
case ')': case ')':
n -= 1 n -= 1
case ';':
return n
} }
} }
return n return n
@ -35,7 +37,7 @@ func tcpInterpreter(conn net.Conn, userinput chan string, out chan interface{},
if len(lines) >= MAX_SEXP_LINES { if len(lines) >= MAX_SEXP_LINES {
return errSexpTooLong return errSexpTooLong
} }
lines = append(lines, line) lines = append(lines, line+"\n")
return nil return nil
} }
errorMode := false errorMode := false
@ -45,10 +47,21 @@ func tcpInterpreter(conn net.Conn, userinput chan string, out chan interface{},
errorMode = false errorMode = false
} }
} }
s := make(chan string)
go func() {
for program := range s {
tokens := make(chan token, 32)
go lexs(program, tokens)
evalall(tokens, out, errors, universe)
}
}()
go func() {
for v := range out {
fmt.Fprintln(conn, v)
}
}()
for { for {
select { select {
case v := <-out:
fmt.Fprintln(manager, v)
case err := <-errors: case err := <-errors:
fmt.Fprintf(conn, "error: %v\n", err) fmt.Fprintf(conn, "error: %v\n", err)
case line := <-userinput: case line := <-userinput:
@ -59,10 +72,14 @@ func tcpInterpreter(conn net.Conn, userinput chan string, out chan interface{},
lineDepth := depth(line) lineDepth := depth(line)
currentDepth += lineDepth currentDepth += lineDepth
if currentDepth < 0 {
lines = lines[:0]
currentDepth = 0
break
}
if len(lines) == 0 && lineDepth == 0 { if len(lines) == 0 && lineDepth == 0 {
tokens := make(chan token, 32) s <- line + "\n"
go lexs(line+"\n", tokens)
go evalall(tokens, out, errors, universe)
break break
} }
@ -74,11 +91,9 @@ func tcpInterpreter(conn net.Conn, userinput chan string, out chan interface{},
} }
if currentDepth == 0 { if currentDepth == 0 {
runnable := strings.Join(lines, " ") program := strings.Join(append(lines, "\n"), " ")
lines = lines[:0] lines = lines[:0]
tokens := make(chan token, 32) s <- program
go lexs(runnable+"\n", tokens)
go evalall(tokens, out, errors, universe)
} }
} }
} }
@ -110,14 +125,12 @@ func startConnection(conn net.Conn, m *cm.Manager) {
r := bufio.NewReader(conn) r := bufio.NewReader(conn)
for { for {
line, prefix, err := r.ReadLine() line, _, err := r.ReadLine()
if prefix {
fmt.Println("(prefix)")
}
switch err { switch err {
case nil: case nil:
break break
case io.EOF: case io.EOF:
io.WriteString(conn, "<eof>")
return return
default: default:
printErrorMsg(err.Error()) printErrorMsg(err.Error())

Loading…
Cancel
Save