Update to tokio 0.3 and bump major version number #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tokio 0.3 removed the
PollEventedstruct, which required restructuring things quite a bit in order to updatetokio-libtls. In the process, I discovered some issues with the previous implementation. This update contains multiple breaking changes, so I bumped the version number to2.0.0. Even without the API changes, increasing the required tokio version is a breaking change by itself, so I don't think there's a way to avoid this.The main problem with the old implementation was that, for the implementations of
AsyncReadandAsyncWrite, the current task was never scheduled to be woken in the future if IO would block. Instead, it simply returnedPoll::Pendingwithout doing anything. Handling this correctly requires registering interest in the socket being either readable or writable, depending on whether the libtls function returnsTLS_WANT_POLLINorTLS_WANT_POLLOUT. I ended up making a helper functionpoll_ioto handle this logic, and removing thetry_async_tlsmacro.Side note: a thing that confused me a lot initially was that
tls_readandtls_writecan both return eitherTLS_WANT_POLLINorTLS_WANT_POLLOUT. I initially assumed thattls_readwould only need the socket to be readable and thattls_writewould only need writable.It turns out that
poll_iois the exact same logic needed for processing the handshake inAsyncTls::poll, so I restructured that section of the code to usepoll_ioinstead of the previous method which involved storing readiness inside of theErrorvariants. I'm not certain whether the old implementation ofAsyncTls::pollever worked correctly, but it was very confusing (for me at least) and polluted the publicErrorenum with variants that would never actually get returned from the function. After removing these extra variants,Errorbecomes redundant because it's only variant isTlsError. At this point I just removed it entirely. This is technically a breaking change, but I also don't thinkErrorwas ever returned from a function, so making it public in the first place was probably a mistake, and I don't imagine any code depending ontokio_libtlsis matching against it. Since we're going to need breaking changes anyways in order to bump the tokio dependency version, we might as well removeError. Another option would be to keepErrorin the public api but mark it as deprecated since it's never constructed.I also removed
AsyncTlsStreamentirely. Previously,AsyncTlsStreamwas useful for exposing thePollEventedmethods publicly, butPollEventedno longer exists, and if you want to poll readable or writable readiness on the socket you can just useTcpStream::poll_read_readyandTcpStream::poll_write_ready. I'm not certain if there are any situations where users would want to do this by hand, but to allow this we could either makeTlsStream::tcppublic or write duplicate methods inTlsStreamthat just call the correspondingTcpStreammethods. Either way the previous functionality ofAsyncTlsStreamis now a part ofTlsStreamand the oldAsyncTlsStreamtype is unnecessary. Following similar reasoning to removingError, I think this is going to have breaking changes anyway so we might as well remove it, but makingtype AsyncTlsStream = TlsStreamand marking it as deprecated is also an option.One last question is whether or not the
tlsandtcpmembers ofTlsStreamshould be marked public. I'm not sure whether there are situations in which users would want direct access to these variables, but if so that's an easy change.