Skip to content

feat(datagrams): add sendable/readable futures and try_send/try_recv methods#2366

Open
Aderinom wants to merge 8 commits intoquinn-rs:mainfrom
Aderinom:feat/try_api
Open

feat(datagrams): add sendable/readable futures and try_send/try_recv methods#2366
Aderinom wants to merge 8 commits intoquinn-rs:mainfrom
Aderinom:feat/try_api

Conversation

@Aderinom
Copy link
Copy Markdown

Related Issues:

Additions:

  • Connection::try_send_datagram and Connection::try_read_datagram, returning WouldBlock when the operation cannot complete immediately
  • Connection::datagram_readable, resolving as soon as any datagram is readable
  • Connection::datagram_sendable, resolving as soon as a specified number of bytes are writable

Copy link
Copy Markdown
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion in #2351, it's not clear what the try_ methods add. I don't want to maintain two copies of every single async function when it's straightforward enough to poll the futures we already have.

If you're not comfortable relying on that without a documented guarantee, feel free to propose some documentation, as @djc suggested. It would be very strange for any future that could complete immediately to return Pending instead, but I don't mind explicitly committing not to.

Comment thread quinn/src/connection.rs Outdated
/// Attempts to receive an application datagram
///
/// If there are no readable datagrams, this will return [TryReceiveDatagramError::WouldBlock]
pub fn try_read_datagram(&self) -> Result<Bytes, TryReceiveDatagramError> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result<Option<Bytes>, ConnectionError> seems much less error-prone, since it separates the exceptional case.

Comment thread quinn-proto/src/connection/datagrams.rs Outdated
Ok(())
}

/// Sets the send_blocked flag to true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The send_blocked flag is not part of the public API, so this is not helpful documentation. Maybe try an imperative phrasing of what you wrote just below?

Comment thread quinn/src/connection.rs Outdated
}
}

/// Creates a future, resolving as soon as a readable datagram is buffered
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't prefix async function documentation with "Creates a future"; it doesn't add information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants