Hi,
I am trying to use boost::thread to copy data from one stream to another.
For this I have written the following code, but can can not compile it
and I do not under stand why...
Is there an better way to do this?
--
Allan
#include <fstream>
#include <iostream>
#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/URI.h"
#include
using namespace std;
using namespace Poco;
using namespace Poco::Net;
struct Test {
Test (const std::string & s_url) :
uri(s_url),
path(uri.getPathAndQuery()),
session(uri.getHost(), uri.getPort()) {
if (path.empty()) path = "/";
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
// Compiler error
// boost::thread(boost::ref(*this)); // this compiles
boost::packaged_task<int> pt(boost::ref(*this));
boost::unique_future<int> fi=pt.get_future();
boost::thread task(boost::move(pt));
}
int operator()() {
ofstream null("/dev/null");
std::istream& rs = session.receiveResponse(res);
StreamCopier::copyStream(rs, null);
}
URI uri;
std::string path;
HTTPClientSession session;
HTTPResponse res;
};
int main(int argc, const char *argv[]) {
Test test("http://localhost/gmbfs");
// TODO, sync
return 0;
}