Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
NETWORKING: Enter Session and SessionRequest #1914
Originally intended to be a speedup for libcurl by reusing the same handle in keep-alive connections. Turns out, libcurl automatically does that.
Anyways, this PR does some useful edits in backends/networking/curl and adds SessionRequest, which might be not only used asynchronously as before (via callbacks), but also synchronously using wait(). Session class allows to reuse these SessionRequests.
It is to be used in a Session, though it might be used separately. It must implement keep-alive, but it does not yet. You must not put it to ConnMan by yourself (instead, use start()) and you must call close() after you've finished using this request. You can either work with it in callback, or wait() and simply use its methods (check it's success() and then, for example, use text()). Like this: ``` Networking::SessionRequest *rq = new Networking::SessionRequest(url); rq->startAndWait(); if (rq->success()) warning("HTTP GET: %s", rq->text()); rq->close(); ```
Session allows to reuse SessionRequests to the same host by making them keeping alive connection. Turns out, though, that libcurl already does that for us, and we didn't gain any speedup we thought we'd get. Usage: ``` Networking::Session s; Networking::SessionRequest *request = s.get(url); request->startAndWait(); warning("HTTP GET: %s", request->text()); s.close(); ``` You can still use SessionRequest without Session (but you can't put them on stack!): ``` Networking::SessionRequest *request = new Networking::SessionRequest(url); request->startAndWait(); warning("HTTP GET: %s", request->text()); request->close(); ```