]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Count errors returned from connection.mainReadLoop
authorMatt Joiner <anacrolix@gmail.com>
Mon, 12 Feb 2018 13:56:21 +0000 (00:56 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 12 Feb 2018 13:56:21 +0000 (00:56 +1100)
connection.go

index 4e919c5faecc468bbfe5c000bc0bfc2dedacc0d4..bf4485746b2057dbe333d9524507bf640ff2a05f 100644 (file)
@@ -960,7 +960,14 @@ func (c *connection) onReadRequest(r request) error {
 
 // Processes incoming bittorrent messages. The client lock is held upon entry
 // and exit. Returning will end the connection.
-func (c *connection) mainReadLoop() error {
+func (c *connection) mainReadLoop() (err error) {
+       defer func() {
+               if err != nil {
+                       torrent.Add("connection.mainReadLoop returned with error", 1)
+               } else {
+                       torrent.Add("connection.mainReadLoop returned with no error", 1)
+               }
+       }()
        t := c.t
        cl := t.cl
 
@@ -970,10 +977,7 @@ func (c *connection) mainReadLoop() error {
                Pool:      t.chunkPool,
        }
        for {
-               var (
-                       msg pp.Message
-                       err error
-               )
+               var msg pp.Message
                func() {
                        cl.mu.Unlock()
                        defer cl.mu.Lock()