#if defined(ENABLE_CURL)
CURLM* curlMulti;
bool haveActiveRequests;
+
+ void createCurlMulti()
+ {
+ curlMulti = curl_multi_init();
+ // see https://curl.haxx.se/libcurl/c/CURLMOPT_PIPELINING.html
+ // we request HTTP 1.1 pipelining
+ curl_multi_setopt(curlMulti, CURLMOPT_PIPELINING, CURLPIPE_HTTP1);
+ curl_multi_setopt(curlMulti, CURLMOPT_MAX_TOTAL_CONNECTIONS, (long) maxConnections);
+ curl_multi_setopt(curlMulti, CURLMOPT_MAX_PIPELINE_LENGTH,
+ (long) MAX_INFLIGHT_REQUESTS);
+
+ }
#else
NetChannelPoller poller;
// connections by host (potentially more than one)
didInitCurlGlobal = true;
}
- d->curlMulti = curl_multi_init();
+ d->createCurlMulti();
#endif
}
d->maxConnections = maxCon;
#if defined(ENABLE_CURL)
- curl_multi_setopt(d->curlMulti, CURLMOPT_MAXCONNECTS, (long) maxCon);
+ curl_multi_setopt(d->curlMulti, CURLMOPT_MAX_TOTAL_CONNECTIONS, (long) maxCon);
#endif
}
curl_easy_setopt(curlRequest, CURLOPT_HEADERDATA, r.get());
curl_easy_setopt(curlRequest, CURLOPT_USERAGENT, d->userAgent.c_str());
+ curl_easy_setopt(curlRequest, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
if (!d->proxy.empty()) {
curl_easy_setopt(curlRequest, CURLOPT_PROXY, d->proxy.c_str());
#endif
}
+void Client::clearAllConnections()
+{
+#if defined(ENABLE_CURL)
+ curl_multi_cleanup(d->curlMulti);
+ d->createCurlMulti();
+#else
+ ConnectionDict::iterator it = d->connections.begin();
+ for (; it != d->connections.end(); ++it) {
+ delete it->second;
+ }
+ d->connections.clear();
+#endif
+}
+
} // of namespace HTTP
} // of namespace simgear
cout << "testing HTTP 1.1 pipelining" << endl;
{
-
+ testServer.resetConnectCount();
+ cl.clearAllConnections();
+
cl.setProxy("", 80);
TestRequest* tr = new TestRequest("http://localhost:2000/test1");
HTTP::Request_ptr own(tr);
COMPARE(tr2->bodyData, string(BODY3));
COMPARE(tr3->bodyData, string(BODY1));
+
+ COMPARE(testServer.connectCount(), 1);
}
// multiple requests with an HTTP 1.0 server
class TestServer : public NetChannel
{
simgear::NetChannelPoller _poller;
+ int _connectCount;
public:
TestServer()
{
Socket::initSockets();
+ _connectCount = 0;
+
open();
bind(NULL, 2000); // localhost, any port
listen(16);
chan->setHandle(handle);
_poller.addChannel(chan);
+
+ _connectCount++;
}
void poll()
{
_poller.poll();
}
+
+ void resetConnectCount()
+ {
+ _connectCount = 0;
+ }
+
+ int connectCount()
+ {
+ return _connectCount;
+ }
};
} // of namespace simgear