diff options
-rwxr-xr-x | server/server/config.cpp | 4 | ||||
-rw-r--r-- | server/server/speedtest.cpp | 22 |
2 files changed, 10 insertions, 16 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp index 5d80cab..7bc4fae 100755 --- a/server/server/config.cpp +++ b/server/server/config.cpp @@ -29,13 +29,13 @@ void speed_test_thread_func(std::list<config::proxy_entry>* proxy_list, std::lis { speedtest t(test_url); t.test(&(*i)); - boost::this_thread::sleep(boost::posix_time::seconds(30)); + boost::this_thread::sleep(boost::posix_time::seconds(2)); } /* for(std::list<config::proxy_entry>::iterator i = proxy_list->begin(), end = proxy_list->end(); i != end; ++i) { speedtest t(test_url); t.test(&(*i)); - boost::this_thread::sleep(boost::posix_time::seconds(30)); + boost::this_thread::sleep(boost::posix_time::seconds(2)); } */ m->unlock(); boost::this_thread::sleep(boost::posix_time::minutes(180)); diff --git a/server/server/speedtest.cpp b/server/server/speedtest.cpp index bbd97d9..4beb9e1 100644 --- a/server/server/speedtest.cpp +++ b/server/server/speedtest.cpp @@ -28,16 +28,12 @@ size_t speedtest::test(config::proxy_entry *p) chunk.size = 0; curl_easy_setopt(curl, CURLOPT_URL, test_url.c_str()); curl_easy_setopt(curl, CURLOPT_PROXY, p->host.c_str()); - char port[8]; - snprintf(port, 7, "%d", p->port); - curl_easy_setopt(curl, CURLOPT_PROXYPORT, port); + curl_easy_setopt(curl, CURLOPT_PROXYPORT, p->port); if(!p->password.empty() && !p->login.empty()) curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, std::string(p->login + ":" + p->password).c_str()); curl_proxytype type = CURLPROXY_HTTP; switch(p->type) { - case config::HTTP: - type = CURLPROXY_HTTP; break; case config::HTTPS: type = CURLPROXY_HTTP; //is it correct ? @@ -57,11 +53,9 @@ size_t speedtest::test(config::proxy_entry *p) curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-speedtest/0.1"); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, "10"); - - timer.restart(); - bool error = curl_easy_perform(curl); + CURLcode error = curl_easy_perform(curl); double time = timer.elapsed(); @@ -70,6 +64,7 @@ size_t speedtest::test(config::proxy_entry *p) free(chunk.memory); if(error) { +// const char *szError = curl_easy_strerror(error); p->speed = -1; return 0; } @@ -95,20 +90,17 @@ size_t speedtest::test(config::static_proxy_entry *p) chunk.size = 0; curl_easy_setopt(curl, CURLOPT_URL, test_url.c_str()); curl_easy_setopt(curl, CURLOPT_PROXY, p->host.c_str()); - char port[8]; - snprintf(port, 7, "%d", p->port); - curl_easy_setopt(curl, CURLOPT_PROXYPORT, port); + curl_easy_setopt(curl, CURLOPT_PROXYPORT, p->port); if(!p->password.empty() && !p->login.empty()) curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, std::string(p->login + ":" + p->password).c_str()); curl_proxytype type = CURLPROXY_HTTP; switch(p->type) { - case config::HTTP: - type = CURLPROXY_HTTP; break; case config::HTTPS: type = CURLPROXY_HTTP; //is it correct ? curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); //required for ssl + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); //maybe required for https proxy ? break; case config::SOCKS4: type = CURLPROXY_SOCKS4; @@ -121,10 +113,11 @@ size_t speedtest::test(config::static_proxy_entry *p) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &speedtest::curl_data_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-speedtest/0.1"); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, "10"); timer.restart(); - bool error = curl_easy_perform(curl); + CURLcode error = curl_easy_perform(curl); double time = timer.elapsed(); @@ -133,6 +126,7 @@ size_t speedtest::test(config::static_proxy_entry *p) free(chunk.memory); if(error) { +// const char *szError = curl_easy_strerror(error); p->speed = -1; return 0; } |