--- a/mercurial/keepalive.py Mon Oct 01 12:06:36 2018 -0700
+++ b/mercurial/keepalive.py Mon Oct 01 12:02:54 2018 -0700
@@ -174,6 +174,8 @@
class KeepAliveHandler(object):
def __init__(self):
self._cm = ConnectionManager()
+ self.requestscount = 0
+ self.sentbytescount = 0
#### Connection Management
def open_connections(self):
@@ -312,6 +314,8 @@
return r
def _start_transaction(self, h, req):
+ oldbytescount = h.sentbytescount
+
# What follows mostly reimplements HTTPConnection.request()
# except it adds self.parent.addheaders in the mix and sends headers
# in a deterministic order (to make testing easier).
@@ -346,6 +350,16 @@
if urllibcompat.hasdata(req):
h.send(data)
+ # This will fail to record events in case of I/O failure. That's OK.
+ self.requestscount += 1
+ self.sentbytescount += h.sentbytescount - oldbytescount
+
+ try:
+ self.parent.requestscount += 1
+ self.parent.sentbytescount += h.sentbytescount - oldbytescount
+ except AttributeError:
+ pass
+
class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
pass
@@ -585,9 +599,11 @@
data = read(blocksize)
while data:
self.sock.sendall(data)
+ self.sentbytescount += len(data)
data = read(blocksize)
else:
self.sock.sendall(str)
+ self.sentbytescount += len(str)
except socket.error as v:
reraise = True
if v[0] == errno.EPIPE: # Broken pipe
@@ -624,6 +640,9 @@
send = safesend
getresponse = wrapgetresponse(httplib.HTTPConnection)
+ def __init__(self, *args, **kwargs):
+ httplib.HTTPConnection.__init__(self, *args, **kwargs)
+ self.sentbytescount = 0
#########################################################################
##### TEST FUNCTIONS