From 6819e1c73cca5165db35960586229028e1ee3722 Mon Sep 17 00:00:00 2001 From: Markus Sintonen Date: Tue, 11 Jun 2024 22:38:40 +0300 Subject: [PATCH] Better var name --- httpcore/_async/http11.py | 11 ++++++----- httpcore/_sync/http11.py | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/httpcore/_async/http11.py b/httpcore/_async/http11.py index 9ee3c6ba..38f4a292 100644 --- a/httpcore/_async/http11.py +++ b/httpcore/_async/http11.py @@ -71,7 +71,8 @@ def __init__( our_role=h11.CLIENT, max_incomplete_event_size=self.MAX_INCOMPLETE_EVENT_SIZE, ) - self._socket_used_at = time.monotonic() + # Assuming we were just connected + self._network_stream_used_at = time.monotonic() async def handle_async_request(self, request: Request) -> Response: if not self.can_handle_request(request.url.origin): @@ -177,7 +178,7 @@ async def _send_event( bytes_to_send = self._h11_state.send(event) if bytes_to_send is not None: await self._network_stream.write(bytes_to_send, timeout=timeout) - self._socket_used_at = time.monotonic() + self._network_stream_used_at = time.monotonic() # Receiving the response... @@ -229,7 +230,7 @@ async def _receive_event( data = await self._network_stream.read( self.READ_NUM_BYTES, timeout=timeout ) - self._socket_used_at = time.monotonic() + self._network_stream_used_at = time.monotonic() # If we feed this case through h11 we'll raise an exception like: # @@ -294,8 +295,8 @@ def has_expired(self) -> bool: # only valid state is that the socket is about to return b"", indicating # a server-initiated disconnect. # Checking the readable status is relatively expensive so check it at a lower frequency. - if (now - self._socket_used_at) > self._socket_poll_interval(): - self._socket_used_at = now + if (now - self._network_stream_used_at) > self._socket_poll_interval(): + self._network_stream_used_at = now server_disconnected = ( self._state == HTTPConnectionState.IDLE and self._network_stream.get_extra_info("is_readable") diff --git a/httpcore/_sync/http11.py b/httpcore/_sync/http11.py index 6da2fc5d..eecfd33c 100644 --- a/httpcore/_sync/http11.py +++ b/httpcore/_sync/http11.py @@ -71,7 +71,8 @@ def __init__( our_role=h11.CLIENT, max_incomplete_event_size=self.MAX_INCOMPLETE_EVENT_SIZE, ) - self._socket_used_at = time.monotonic() + # Assuming we were just connected + self._network_stream_used_at = time.monotonic() def handle_request(self, request: Request) -> Response: if not self.can_handle_request(request.url.origin): @@ -177,7 +178,7 @@ def _send_event( bytes_to_send = self._h11_state.send(event) if bytes_to_send is not None: self._network_stream.write(bytes_to_send, timeout=timeout) - self._socket_used_at = time.monotonic() + self._network_stream_used_at = time.monotonic() # Receiving the response... @@ -229,7 +230,7 @@ def _receive_event( data = self._network_stream.read( self.READ_NUM_BYTES, timeout=timeout ) - self._socket_used_at = time.monotonic() + self._network_stream_used_at = time.monotonic() # If we feed this case through h11 we'll raise an exception like: # @@ -294,8 +295,8 @@ def has_expired(self) -> bool: # only valid state is that the socket is about to return b"", indicating # a server-initiated disconnect. # Checking the readable status is relatively expensive so check it at a lower frequency. - if (now - self._socket_used_at) > self._socket_poll_interval(): - self._socket_used_at = now + if (now - self._network_stream_used_at) > self._socket_poll_interval(): + self._network_stream_used_at = now server_disconnected = ( self._state == HTTPConnectionState.IDLE and self._network_stream.get_extra_info("is_readable")