|
@@ -33,6 +33,9 @@ type Socket struct {
|
33
|
33
|
sendQExceeded bool
|
34
|
34
|
finalData []byte // what to send when we die
|
35
|
35
|
finalized bool
|
|
36
|
+
|
|
37
|
+ bytesRead uint64
|
|
38
|
+ bytesWritten uint64
|
36
|
39
|
}
|
37
|
40
|
|
38
|
41
|
// NewSocket returns a new Socket.
|
|
@@ -53,6 +56,12 @@ func (socket *Socket) Close() {
|
53
|
56
|
socket.wakeWriter()
|
54
|
57
|
}
|
55
|
58
|
|
|
59
|
+func (socket *Socket) Stats() (bytesRead, bytesWritten uint64) {
|
|
60
|
+ socket.Lock()
|
|
61
|
+ defer socket.Unlock()
|
|
62
|
+ return socket.bytesRead, socket.bytesWritten
|
|
63
|
+}
|
|
64
|
+
|
56
|
65
|
// Read returns a single IRC line from a Socket.
|
57
|
66
|
func (socket *Socket) Read() (string, error) {
|
58
|
67
|
// immediately fail if Close() has been called, even if there's
|
|
@@ -64,6 +73,10 @@ func (socket *Socket) Read() (string, error) {
|
64
|
73
|
lineBytes, err := socket.conn.ReadLine()
|
65
|
74
|
line := string(lineBytes)
|
66
|
75
|
|
|
76
|
+ socket.Lock()
|
|
77
|
+ socket.bytesRead += uint64(len(lineBytes))
|
|
78
|
+ socket.Unlock()
|
|
79
|
+
|
67
|
80
|
if err == io.EOF {
|
68
|
81
|
socket.Close()
|
69
|
82
|
}
|
|
@@ -93,6 +106,7 @@ func (socket *Socket) Write(data []byte) (err error) {
|
93
|
106
|
} else {
|
94
|
107
|
socket.buffers = append(socket.buffers, data)
|
95
|
108
|
socket.totalLength = prospectiveLen
|
|
109
|
+ socket.bytesWritten += uint64(len(data))
|
96
|
110
|
}
|
97
|
111
|
}
|
98
|
112
|
socket.Unlock()
|
|
@@ -134,6 +148,10 @@ func (socket *Socket) BlockingWrite(data []byte) (err error) {
|
134
|
148
|
return io.EOF
|
135
|
149
|
}
|
136
|
150
|
|
|
151
|
+ socket.Lock()
|
|
152
|
+ socket.bytesWritten += uint64(len(data))
|
|
153
|
+ socket.Unlock()
|
|
154
|
+
|
137
|
155
|
err = socket.conn.WriteLine(data)
|
138
|
156
|
if err != nil {
|
139
|
157
|
socket.finalize()
|