1
0
Fork 0
forked from External/ergo

Make debugging messages easier to turn off.

This commit is contained in:
Jeremy Latt 2013-05-11 14:43:06 -07:00
parent 2ff93d74be
commit 8e5ff51257
6 changed files with 52 additions and 13 deletions

View file

@ -2,10 +2,15 @@ package irc
import (
"bufio"
"log"
"net"
"strings"
)
const (
DEBUG_NET = false
)
func readTrimmedLine(reader *bufio.Reader) (string, error) {
line, err := reader.ReadString('\n')
if err != nil {
@ -24,6 +29,9 @@ func StringReadChan(conn net.Conn) <-chan string {
if err != nil {
break
}
if DEBUG_NET {
log.Printf("%s → %s", conn.RemoteAddr(), line)
}
ch <- line
}
close(ch)
@ -36,7 +44,10 @@ func StringWriteChan(conn net.Conn) chan<- string {
writer := bufio.NewWriter(conn)
go func() {
for str := range ch {
if _, err := writer.WriteString(str); err != nil {
if DEBUG_NET {
log.Printf("%s ← %s", conn.RemoteAddr(), str)
}
if _, err := writer.WriteString(str + "\r\n"); err != nil {
break
}
writer.Flush()