Add missing is_readable method to AsyncSocket for httpx compatibility
This commit is contained in:
parent
8e0f1ac88c
commit
9b6735b924
|
@ -1,3 +1,4 @@
|
|||
import select
|
||||
import warnings
|
||||
import platform
|
||||
from typing import Any
|
||||
|
@ -655,5 +656,20 @@ class AsyncSocket(AsyncResource):
|
|||
except WantWrite:
|
||||
await wait_writable(self._fd)
|
||||
|
||||
def is_readable(self):
|
||||
"""
|
||||
Returns whether the OS thinks this socket is
|
||||
readable. For more info see https://github.com/python-trio/trio/issues/760
|
||||
"""
|
||||
|
||||
match platform.system():
|
||||
case "Windows":
|
||||
readable, _, _ = select.select([self.socket], [], [], 0)
|
||||
return bool(readable)
|
||||
case _:
|
||||
p = select.poll()
|
||||
p.register(self.socket, select.POLLIN)
|
||||
return bool(p.poll(0))
|
||||
|
||||
def __repr__(self):
|
||||
return f"AsyncSocket({self.socket})"
|
||||
|
|
Loading…
Reference in New Issue