-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a new is_readable method to SocketType (fix #760) #1137
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
We added a new ``is_readable`` method to the ``trio.socket.SocketType`` | ||
object that allows you to check whether a socket is ready to be read | ||
or not. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,6 +404,23 @@ async def test_SocketType_simple_server(address, socket_type): | |
assert await client.recv(1) == b"x" | ||
|
||
|
||
async def test_SocketTupe_is_readable(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: "SocketTupe" should be "SocketType" |
||
listener = tsocket.socket(tsocket.AF_INET) | ||
client = tsocket.socket(tsocket.AF_INET) | ||
with listener, client: | ||
await listener.bind(('127.0.0.1', 0)) | ||
listener.listen(20) | ||
addr = listener.getsockname()[:2] | ||
async with _core.open_nursery() as nursery: | ||
nursery.start_soon(client.connect, addr) | ||
server, client_addr = await listener.accept() | ||
with server: | ||
assert not client.is_readable() | ||
await server.send(b"x") | ||
assert client.is_readable() | ||
assert await client.recv(1) == b"x" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified a lot by using a, b = trio.socket.socketpair()
with a, b:
assert not a.is_readable()
await b.send(b"x")
await _core.wait_readable(a)
assert a.is_readable()
assert await a.recv(1) == b"x"
assert not a.is_readable() I also added a call to |
||
|
||
|
||
# On some macOS systems, getaddrinfo likes to return V4-mapped addresses even | ||
# when we *don't* pass AI_V4MAPPED. | ||
# https://github.com/python-trio/trio/issues/580 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double-backticks are raw code; since we're referring to objects that have entries in the documentation, we can use single-backticks to link directly:
(The tilde is a shorthand that means "make a link to
trio.socket.SocketType.is_readable
, but just render it asis_readable
".)