Making the 'httpsrc' plugin asynchronous | GSoC 2019
Although the Rust version of the plugin is working, it is not feature complete. So my task here is to finish 'rshttpsrc' plugin completely. Let me break the task into smaller branches.
- Switching to async IO (Currently it is making request synchronously).
- Support for cookie/HTTP connection sharing between multiple instances.
- Making 'rshttpsrc' feature equivalent to 'souphttpsrc' (the C version of the same plugin). There are properties missing in 'rshttpsrc' which are implemented in C version of the plugin. Here is the list of properties in C version of the plugin.
'rshttpsrc' is using 'reqwest' for making HTTP/HTTPS request. Our plugin was using the synchronous Client of the 'reqwest' crate which pretty much explain why the requests were synchronous. All I had to do to make it asynchronous was introducing async Client of the reqwest. But when doing this conversion I had to change the code that is wrapped around the method which makes the call to the specified URI and modify the methods which handle the request.
Basically 'do_request()' method makes the call specified by the URI and gets the response asynchronously while 'create()' method is called by Gstreamer when data is needed. So 'create()' is invoked with the data from the response. These were some of the places in the code that I had to modify.
'wait()' is an interesting function introduced newly to cater asynchronous feature. It was previously implemented in 's3' plugin. This is what the function does. It gets a input of a Future (something that take time to resolve) which resolves either into an error or an item. Basically this gives you an API that allows to run some operation that takes time, but allows to cancel it at any time without having to wait until it finishes.
Switching to async IO for 'rshttpsrc' is done. Let's discuss the next part of the problem in the upcoming blogs :)
Comments
Post a Comment