I want to program a HTTP client with boost. I could use the asynchronous model if I manage to do the following:
- In a first step, send the request to the server.
- In a second step, either read the the response that has already arrived or wait synchronously until it arrives.
This is a class that looks similar to what I have produce:
class HTTPClient {
public:
void sendTheRequest(...) {
// Send the HTTP request
}
std::string getTheResponse(...) {
// return the already (asynchronously) received response, or wait for it
// in this function
}
}
Can someone point out how to realize this? I fear I am lacking the knowledge in boost.
Edit for clarification: The method sendTheRequest will be called at a point. Maybe directly after it getTheResponse will be called, but this can also happen some (milli)seconds later. Thats why I want to send the request asynchronously, but need to wait for it synchronously too.
Mabye a bit late, but I think this should do it.
std::future::getreturns the value of the send_request_function or waits if that didn’t return yet and returns it after it has completed.