Using TLS in Rusttokio ain’t for mere mortals
I kept going with tokio for a while, I even got something that I think would eventually work. The whole concept is around streams, so I create a way to generate them. This is basically taking this code and making it async.
I gave up well into the second hour. Here is where I stopped:
I gave up when I realized that the reader I’m using (which is SslStream) didn’t seem to have poll_read. The way I’m reading the code, it is supposed to, but I just threw up my hands at disgust at this time. If it this hard, it ain’t going to happen.
I wrote significant amount of async code in C# at the time when events and callbacks were the only option and then when the TPL and ContinueWith was the way to go. That was hard, and async/await is a welcome relief, but the level of frustration and “is this wrong, or am I really this stupid?” that I got midway through is far too much.
Note that this isn’t even about Rust. Some number of issues that I run into were because of Rust, but the major issue that I have here is that I’m trying to write a function that can be expressed in a sync manner in less than 15 lines of code and took me about 10 minutes to write the first time. And after spending more hours than I’m comfortable admitting, I couldn’t get it to work. The programming model you have here, even if everything did work, means that you have to either decompose your behavior to streams and interact with them in this manner or you put everything as nested lambdas.
Either option doesn’t make for a nice model to work with. I believe that there is another async I/O model for Rust, the MIO crate, which is based on the event loop model. I’ve already implemented that in C, so that might be a more natural way to do things.
More posts in "Using TLS in Rust" series:
- (31 Jan 2019) Handling messages out of band
- (29 Jan 2019) The complexity of async, macros and madness
- (25 Jan 2019) Getting async I/O with tokio, second try
- (23 Jan 2019) tokio ain’t for mere mortals
- (21 Jan 2019) Going to async I/O with Tokio
tokio ain’t for mere mortals?
Try nim async/await... You will feel at (C#) home and fast as C++