Skip to content

Commit

Permalink
Better var name
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusSintonen committed Jun 11, 2024
1 parent 05b1844 commit 85304cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions httpcore/_async/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(
our_role=h11.CLIENT,
max_incomplete_event_size=self.MAX_INCOMPLETE_EVENT_SIZE,
)
self._prev_socket_use_time = time.monotonic()
self._socket_used_at = time.monotonic()

async def handle_async_request(self, request: Request) -> Response:
if not self.can_handle_request(request.url.origin):
Expand Down Expand Up @@ -177,7 +177,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._prev_socket_use_time = time.monotonic()
self._socket_used_at = time.monotonic()

# Receiving the response...

Expand Down Expand Up @@ -229,7 +229,7 @@ async def _receive_event(
data = await self._network_stream.read(
self.READ_NUM_BYTES, timeout=timeout
)
self._prev_socket_use_time = time.monotonic()
self._socket_used_at = time.monotonic()

# If we feed this case through h11 we'll raise an exception like:
#
Expand Down Expand Up @@ -294,15 +294,16 @@ 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._prev_socket_use_time) > self._socket_poll_interval():
self._prev_socket_use_time = now
if (now - self._socket_used_at) > self._socket_poll_interval():
self._socket_used_at = now
server_disconnected = (
self._state == HTTPConnectionState.IDLE
and self._network_stream.get_extra_info("is_readable")
)
return server_disconnected
else:
return False
if server_disconnected:
return True

return False

def _socket_poll_interval(self) -> float:
# Randomize to avoid polling for all the connections at once
Expand Down
17 changes: 9 additions & 8 deletions httpcore/_sync/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(
our_role=h11.CLIENT,
max_incomplete_event_size=self.MAX_INCOMPLETE_EVENT_SIZE,
)
self._prev_socket_use_time = time.monotonic()
self._socket_used_at = time.monotonic()

def handle_request(self, request: Request) -> Response:
if not self.can_handle_request(request.url.origin):
Expand Down Expand Up @@ -177,7 +177,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._prev_socket_use_time = time.monotonic()
self._socket_used_at = time.monotonic()

# Receiving the response...

Expand Down Expand Up @@ -229,7 +229,7 @@ def _receive_event(
data = self._network_stream.read(
self.READ_NUM_BYTES, timeout=timeout
)
self._prev_socket_use_time = time.monotonic()
self._socket_used_at = time.monotonic()

# If we feed this case through h11 we'll raise an exception like:
#
Expand Down Expand Up @@ -294,15 +294,16 @@ 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._prev_socket_use_time) > self._socket_poll_interval():
self._prev_socket_use_time = now
if (now - self._socket_used_at) > self._socket_poll_interval():
self._socket_used_at = now
server_disconnected = (
self._state == HTTPConnectionState.IDLE
and self._network_stream.get_extra_info("is_readable")
)
return server_disconnected
else:
return False
if server_disconnected:
return True

return False

def _socket_poll_interval(self) -> float:
# Randomize to avoid polling for all the connections at once
Expand Down

0 comments on commit 85304cd

Please sign in to comment.