From 9e619742887f686aec1059283316ed389443cdf3 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 14 Jan 2016 19:05:37 +0100 Subject: improve flow control --- libmproxy/protocol/http.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 8315aed0..7ea5f57d 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -141,6 +141,9 @@ class SafeH2Connection(H2Connection): self.conn.send(self.data_to_send()) def safe_increment_flow_control(self, stream_id, length): + if length == 0: + return + with self.lock: self.increment_flow_control_window(length) self.conn.send(self.data_to_send()) @@ -152,7 +155,7 @@ class SafeH2Connection(H2Connection): def safe_reset_stream(self, stream_id, error_code): with self.lock: self.reset_stream(stream_id, error_code) - self.conn.send(self.h2.data_to_send()) + self.conn.send(self.data_to_send()) def safe_acknowledge_settings(self, event): with self.conn.h2.lock: @@ -174,9 +177,17 @@ class SafeH2Connection(H2Connection): max_outbound_frame_size = self.max_outbound_frame_size for i in xrange(0, len(chunk), max_outbound_frame_size): frame_chunk = chunk[i:i+max_outbound_frame_size] - with self.lock: - self.send_data(stream_id, frame_chunk) - self.conn.send(self.data_to_send()) + + self.lock.acquire() + while True: + if self.local_flow_control_window(stream_id) < len(frame_chunk): + self.lock.release() + time.sleep(0) + else: + break + self.send_data(stream_id, frame_chunk) + self.conn.send(self.data_to_send()) + self.lock.release() with self.lock: self.end_stream(stream_id) self.conn.send(self.data_to_send()) -- cgit v1.2.3