@@ -72,7 +72,7 @@ def __init__(self,
72
72
# one for data being sent to us.
73
73
self ._in_window_manager = window_manager
74
74
75
- # Save off a reference to the state machine.
75
+ # Save off a reference to the state machine wrapped with lock .
76
76
self ._conn = connection
77
77
78
78
# Save off a data callback.
@@ -94,8 +94,9 @@ def send_headers(self, end_stream=False):
94
94
Sends the complete saved header block on the stream.
95
95
"""
96
96
headers = self .get_headers ()
97
- self ._conn .send_headers (self .stream_id , headers , end_stream )
98
- self ._send_cb (self ._conn .data_to_send ())
97
+ with self ._conn as conn :
98
+ conn .send_headers (self .stream_id , headers , end_stream )
99
+ self ._send_cb (conn .data_to_send ())
99
100
100
101
if end_stream :
101
102
self .local_closed = True
@@ -186,10 +187,11 @@ def receive_data(self, event):
186
187
self .data .append (event .data )
187
188
188
189
if increment and not self .remote_closed :
189
- self ._conn .increment_flow_control_window (
190
- increment , stream_id = self .stream_id
191
- )
192
- self ._send_cb (self ._conn .data_to_send ())
190
+ with self ._conn as conn :
191
+ conn .increment_flow_control_window (
192
+ increment , stream_id = self .stream_id
193
+ )
194
+ self ._send_cb (conn .data_to_send ())
193
195
194
196
def receive_end_stream (self , event ):
195
197
"""
@@ -277,16 +279,17 @@ def close(self, error_code=None):
277
279
"""
278
280
# FIXME: I think this is overbroad, but for now it's probably ok.
279
281
if not (self .remote_closed and self .local_closed ):
280
- try :
281
- self ._conn .reset_stream (self .stream_id , error_code or 0 )
282
- except h2 .exceptions .ProtocolError :
283
- # If for any reason we can't reset the stream, just tolerate
284
- # it.
285
- pass
286
- else :
287
- self ._send_cb (
288
- self ._conn .data_to_send (), tolerate_peer_gone = True
289
- )
282
+ with self ._conn as conn :
283
+ try :
284
+ conn .reset_stream (self .stream_id , error_code or 0 )
285
+ except h2 .exceptions .ProtocolError :
286
+ # If for any reason we can't reset the stream, just tolerate
287
+ # it.
288
+ pass
289
+ else :
290
+ self ._send_cb (
291
+ conn .data_to_send (), tolerate_peer_gone = True
292
+ )
290
293
self .remote_closed = True
291
294
self .local_closed = True
292
295
@@ -297,7 +300,8 @@ def _out_flow_control_window(self):
297
300
"""
298
301
The size of our outbound flow control window.
299
302
"""
300
- return self ._conn .local_flow_control_window (self .stream_id )
303
+
304
+ return self ._conn ._obj .local_flow_control_window (self .stream_id )
301
305
302
306
def _send_chunk (self , data , final ):
303
307
"""
@@ -321,10 +325,11 @@ def _send_chunk(self, data, final):
321
325
end_stream = True
322
326
323
327
# Send the frame and decrement the flow control window.
324
- self ._conn .send_data (
325
- stream_id = self .stream_id , data = data , end_stream = end_stream
326
- )
327
- self ._send_cb (self ._conn .data_to_send ())
328
+ with self ._conn as conn :
329
+ conn .send_data (
330
+ stream_id = self .stream_id , data = data , end_stream = end_stream
331
+ )
332
+ self ._send_cb (conn .data_to_send ())
328
333
329
334
if end_stream :
330
335
self .local_closed = True
0 commit comments