|
@@ -7,7 +7,6 @@ package irc
|
7
|
7
|
import (
|
8
|
8
|
"errors"
|
9
|
9
|
"io"
|
10
|
|
- "strings"
|
11
|
10
|
"sync"
|
12
|
11
|
|
13
|
12
|
"github.com/oragono/oragono/irc/utils"
|
|
@@ -59,30 +58,24 @@ func (socket *Socket) Close() {
|
59
|
58
|
|
60
|
59
|
// Read returns a single IRC line from a Socket.
|
61
|
60
|
func (socket *Socket) Read() (string, error) {
|
|
61
|
+ // immediately fail if Close() has been called, even if there's
|
|
62
|
+ // still data in a bufio.Reader or websocket buffer:
|
62
|
63
|
if socket.IsClosed() {
|
63
|
64
|
return "", io.EOF
|
64
|
65
|
}
|
65
|
66
|
|
66
|
67
|
lineBytes, err := socket.conn.ReadLine()
|
67
|
|
-
|
68
|
|
- // convert bytes to string
|
69
|
68
|
line := string(lineBytes)
|
70
|
69
|
|
71
|
|
- // read last message properly (such as ERROR/QUIT/etc), just fail next reads/writes
|
72
|
70
|
if err == io.EOF {
|
73
|
71
|
socket.Close()
|
|
72
|
+ // process last message properly (such as ERROR/QUIT/etc), just fail next reads/writes
|
|
73
|
+ if line != "" {
|
|
74
|
+ err = nil
|
|
75
|
+ }
|
74
|
76
|
}
|
75
|
77
|
|
76
|
|
- if err == io.EOF && strings.TrimSpace(line) != "" {
|
77
|
|
- // don't do anything
|
78
|
|
- } else if err == errInvalidUtf8 {
|
79
|
|
- // pass the data through so we can parse the command at least
|
80
|
|
- return line, err
|
81
|
|
- } else if err != nil {
|
82
|
|
- return "", err
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
- return line, nil
|
|
78
|
+ return line, err
|
86
|
79
|
}
|
87
|
80
|
|
88
|
81
|
// Write sends the given string out of Socket. Requirements:
|