Encode semantics of Session::keepalive_send in return type
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 566
- Forks
- 163
- Avg merge
- 4h 51m
- Merged PRs (30d)
- 2
Description
Issue
The current implementation of Session::keepalive_send returns Result<u32, Error>. Users might suspect that if they receive an Ok(seconds) they should act on it and send another keep alive message after seconds has elapsed.
However, this is not the case if keepalive is disabled for the session since Session::keepalive_send will return Ok(0) indicating that keepalive is not set. Here's where that happens in libssh2:
if(!session->keepalive_interval) {
if(seconds_to_next)
*seconds_to_next = 0;
return 0;
}
Possible Solutions
The most lightweight thing we can do is update the documentation for Session::keepalive_send so that it clearly indicates that users will get an Ok(0) back if keep alive is not set.
Alternatively, if we're alright with a breaking change for the next minor version release we could change the return type to Result<Option<NonZeroU32>, Error>, or Result<Option<Duration>, Error> and set the option to None if the C api returns zero. I think this is the best way to prevent accidental misuse of the API, but it does require a breaking change.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Session::keepalive_send in session.rs and compare its documented return value with the keepalive.c behavior linked in the issue. Confirm whether the documentation-only option is preferred, then make the result explicit for the disabled-keepalive case; done means users can tell that Ok(0) means no keepalive is configured.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- api
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100