##// END OF EJS Templates
keepalive: track request count and bytes sent...
Gregory Szorc -
r40068:dc82ad1b default
parent child Browse files
Show More
@@ -174,6 +174,8 b' class ConnectionManager(object):'
174 class KeepAliveHandler(object):
174 class KeepAliveHandler(object):
175 def __init__(self):
175 def __init__(self):
176 self._cm = ConnectionManager()
176 self._cm = ConnectionManager()
177 self.requestscount = 0
178 self.sentbytescount = 0
177
179
178 #### Connection Management
180 #### Connection Management
179 def open_connections(self):
181 def open_connections(self):
@@ -312,6 +314,8 b' class KeepAliveHandler(object):'
312 return r
314 return r
313
315
314 def _start_transaction(self, h, req):
316 def _start_transaction(self, h, req):
317 oldbytescount = h.sentbytescount
318
315 # What follows mostly reimplements HTTPConnection.request()
319 # What follows mostly reimplements HTTPConnection.request()
316 # except it adds self.parent.addheaders in the mix and sends headers
320 # except it adds self.parent.addheaders in the mix and sends headers
317 # in a deterministic order (to make testing easier).
321 # in a deterministic order (to make testing easier).
@@ -346,6 +350,16 b' class KeepAliveHandler(object):'
346 if urllibcompat.hasdata(req):
350 if urllibcompat.hasdata(req):
347 h.send(data)
351 h.send(data)
348
352
353 # This will fail to record events in case of I/O failure. That's OK.
354 self.requestscount += 1
355 self.sentbytescount += h.sentbytescount - oldbytescount
356
357 try:
358 self.parent.requestscount += 1
359 self.parent.sentbytescount += h.sentbytescount - oldbytescount
360 except AttributeError:
361 pass
362
349 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
363 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
350 pass
364 pass
351
365
@@ -585,9 +599,11 b' def safesend(self, str):'
585 data = read(blocksize)
599 data = read(blocksize)
586 while data:
600 while data:
587 self.sock.sendall(data)
601 self.sock.sendall(data)
602 self.sentbytescount += len(data)
588 data = read(blocksize)
603 data = read(blocksize)
589 else:
604 else:
590 self.sock.sendall(str)
605 self.sock.sendall(str)
606 self.sentbytescount += len(str)
591 except socket.error as v:
607 except socket.error as v:
592 reraise = True
608 reraise = True
593 if v[0] == errno.EPIPE: # Broken pipe
609 if v[0] == errno.EPIPE: # Broken pipe
@@ -624,6 +640,9 b' class HTTPConnection(httplib.HTTPConnect'
624 send = safesend
640 send = safesend
625 getresponse = wrapgetresponse(httplib.HTTPConnection)
641 getresponse = wrapgetresponse(httplib.HTTPConnection)
626
642
643 def __init__(self, *args, **kwargs):
644 httplib.HTTPConnection.__init__(self, *args, **kwargs)
645 self.sentbytescount = 0
627
646
628 #########################################################################
647 #########################################################################
629 ##### TEST FUNCTIONS
648 ##### TEST FUNCTIONS
General Comments 0
You need to be logged in to leave comments. Login now