@@ -463,33 +463,16 @@ def _reset(self):
463
463
state machine and connection or not, and if not, closes the socket and
464
464
state machine.
465
465
"""
466
- # The logic here is as follows. Once we've got EndOfMessage, only two
467
- # things can be true. Either a) the connection is suitable for
468
- # connection re-use per RFC 7230, or b) it is not. h11 signals this
469
- # difference by what happens when you call `next_event()`.
470
- #
471
- # If the connection is safe to re-use, when we call `next_event()`
472
- # we'll get back a h11.NEED_DATA and the state machine will be reset to
473
- # (IDLE, IDLE). If it's not, we'll get either ConnectionClosed or we'll
474
- # find that our state is MUST_CLOSE, and then we should close the
475
- # connection accordingly.
476
- continue_states = (h11 .IDLE , h11 .DONE )
477
- event = self ._state_machine .next_event ()
478
- our_state = self ._state_machine .our_state
479
- their_state = self ._state_machine .their_state
480
- must_close = (
481
- event is not h11 .NEED_DATA or
482
- our_state not in continue_states or
483
- their_state not in continue_states
484
- )
485
- if must_close :
486
- self .close ()
487
- elif our_state is h11 .DONE and their_state is h11 .DONE :
466
+ try :
488
467
self ._state_machine .start_next_cycle ()
489
- # This connection can be returned to the connection pool, and
490
- # eventually we'll take it out again and want to know if it's been
491
- # dropped.
492
- self ._sock .set_readable_watch_state (True )
468
+ except h11 .LocalProtocolError :
469
+ # Not re-usable
470
+ self .close ()
471
+ else :
472
+ # This connection can be returned to the connection pool, and
473
+ # eventually we'll take it out again and want to know if it's been
474
+ # dropped.
475
+ self ._sock .set_readable_watch_state (True )
493
476
494
477
@property
495
478
def complete (self ):
0 commit comments