(cleanup)

master
Jordan Orelli 12 years ago
parent 10c674b7f3
commit 55e08628c0

@ -7,11 +7,12 @@ import (
"os" "os"
) )
var tcpAddr = flag.String("tcp", "", "foo") var (
tcpAddr = flag.String("tcp", "", "tcp ip:port to listen on")
)
func runfile() { func runfile() {
filename := flag.Args()[0] filename := flag.Args()[0]
fmt.Println(filename)
f, err := os.Open(filename) f, err := os.Open(filename)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "unable to read file ", filename) fmt.Fprintln(os.Stderr, "unable to read file ", filename)

@ -73,10 +73,16 @@ func (i interpreter) send() {
for { for {
select { select {
case v := <-i.values: case v := <-i.values:
if i.out1 == nil {
return
}
if _, err := fmt.Fprintln(i.out1, v); err != nil { if _, err := fmt.Fprintln(i.out1, v); err != nil {
fmt.Println("can't write out to client: ", err) fmt.Println("can't write out to client: ", err)
} }
case e := <-i.errors: case e := <-i.errors:
if i.out2 == nil {
return
}
if _, err := fmt.Fprintln(i.out2, e); err != nil { if _, err := fmt.Fprintln(i.out2, e); err != nil {
fmt.Println("can't write error to client: ", err) fmt.Println("can't write error to client: ", err)
} }

@ -204,7 +204,6 @@ func main() {
} }
if *tcpAddr != "" { if *tcpAddr != "" {
runTCPServer() runTCPServer()
return
} }
if len(flag.Args()) > 0 { if len(flag.Args()) > 0 {
runfile() runfile()

@ -24,11 +24,11 @@ func runTCPServer() {
printErrorMsg(err.Error()) printErrorMsg(err.Error())
continue continue
} }
go startConnection(conn, manager) go startTCPConnection(conn, manager)
} }
} }
func startConnection(conn net.Conn, m *cm.Manager) { func startTCPConnection(conn net.Conn, m *cm.Manager) {
m.Add(conn) m.Add(conn)
defer m.Remove(conn) defer m.Remove(conn)

Loading…
Cancel
Save