3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

flag socket as closed when writes fail

This commit is contained in:
Jeremy Latt 2014-02-23 17:16:35 -08:00
parent 0bf968e19e
commit 0856a9fa81

View File

@ -60,6 +60,7 @@ func (socket *Socket) readLines(commands chan<- Command) {
for { for {
line, err := socket.reader.ReadString('\n') line, err := socket.reader.ReadString('\n')
if socket.isError(err, R) { if socket.isError(err, R) {
socket.closed = true
break break
} }
line = strings.TrimRight(line, "\r\n") line = strings.TrimRight(line, "\r\n")
@ -91,14 +92,17 @@ func (socket *Socket) Write(line string) (err error) {
return io.EOF return io.EOF
} }
if _, err = socket.writer.WriteString(line); socket.isError(err, W) { if _, err = socket.writer.WriteString(line); socket.isError(err, W) {
socket.closed = true
return return
} }
if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) { if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) {
socket.closed = true
return return
} }
if err = socket.writer.Flush(); socket.isError(err, W) { if err = socket.writer.Flush(); socket.isError(err, W) {
socket.closed = true
return return
} }