|
@@ -35,6 +35,9 @@ type Socket struct {
|
35
|
35
|
sendQExceeded bool
|
36
|
36
|
finalData []byte // what to send when we die
|
37
|
37
|
finalized bool
|
|
38
|
+
|
|
39
|
+ bytesRead uint64
|
|
40
|
+ bytesWritten uint64
|
38
|
41
|
}
|
39
|
42
|
|
40
|
43
|
// NewSocket returns a new Socket.
|
|
@@ -56,6 +59,12 @@ func (socket *Socket) Close() {
|
56
|
59
|
socket.wakeWriter()
|
57
|
60
|
}
|
58
|
61
|
|
|
62
|
+func (socket *Socket) Stats() (bytesRead, bytesWritten uint64) {
|
|
63
|
+ socket.Lock()
|
|
64
|
+ defer socket.Unlock()
|
|
65
|
+ return socket.bytesRead, socket.bytesWritten
|
|
66
|
+}
|
|
67
|
+
|
59
|
68
|
// Read returns a single IRC line from a Socket.
|
60
|
69
|
func (socket *Socket) Read() (string, error) {
|
61
|
70
|
// immediately fail if Close() has been called, even if there's
|
|
@@ -67,6 +76,10 @@ func (socket *Socket) Read() (string, error) {
|
67
|
76
|
lineBytes, err := socket.conn.ReadLine()
|
68
|
77
|
line := string(lineBytes)
|
69
|
78
|
|
|
79
|
+ socket.Lock()
|
|
80
|
+ socket.bytesRead += uint64(len(lineBytes))
|
|
81
|
+ socket.Unlock()
|
|
82
|
+
|
70
|
83
|
if err == io.EOF {
|
71
|
84
|
socket.Close()
|
72
|
85
|
}
|
|
@@ -96,6 +109,7 @@ func (socket *Socket) Write(data []byte) (err error) {
|
96
|
109
|
} else {
|
97
|
110
|
socket.buffers = append(socket.buffers, data)
|
98
|
111
|
socket.totalLength = prospectiveLen
|
|
112
|
+ socket.bytesWritten += uint64(len(data))
|
99
|
113
|
}
|
100
|
114
|
}
|
101
|
115
|
socket.Unlock()
|
|
@@ -136,6 +150,10 @@ func (socket *Socket) BlockingWrite(data []byte) (err error) {
|
136
|
150
|
return io.EOF
|
137
|
151
|
}
|
138
|
152
|
|
|
153
|
+ socket.Lock()
|
|
154
|
+ socket.bytesWritten += uint64(len(data))
|
|
155
|
+ socket.Unlock()
|
|
156
|
+
|
139
|
157
|
err = socket.conn.WriteLine(data)
|
140
|
158
|
if err != nil {
|
141
|
159
|
socket.finalize()
|