summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rwxr-xr-xserver/server/config.cpp2
-rw-r--r--server/server/speedtest.cpp23
2 files changed, 18 insertions, 7 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp
index cf218f4..3c7a679 100755
--- a/server/server/config.cpp
+++ b/server/server/config.cpp
@@ -29,7 +29,7 @@ void speed_test_thread_func(int check_interval, std::list<config::proxy_entry>*
for(std::list<config::static_proxy_entry>::iterator i = static_proxy_list->begin(), end = static_proxy_list->end(); i != end; ++i)
{
speedtest t(test_url);
- //*l<<i->host<<" "<<(int)t.test(&(*i))<<"\n";
+// *l<<i->host<<" "<<(int)t.test(&(*i))<<"\n";
t.test(&(*i));
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
diff --git a/server/server/speedtest.cpp b/server/server/speedtest.cpp
index 21fe21c..ecfec2e 100644
--- a/server/server/speedtest.cpp
+++ b/server/server/speedtest.cpp
@@ -40,10 +40,10 @@ size_t speedtest::test(config::proxy_entry_base *p)
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); //maybe required for https proxy ?
break;
case config::SOCKS4:
- type = CURLPROXY_SOCKS4;
+ type = CURLPROXY_SOCKS4A;
break;
case config::SOCKS5:
- type = CURLPROXY_SOCKS5;
+ type = CURLPROXY_SOCKS5_HOSTNAME;
break;
}
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, type);
@@ -51,12 +51,23 @@ size_t speedtest::test(config::proxy_entry_base *p)
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);
+ //curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1); //require latest curl (.25)
- time_t start = time(0);
+ boost::posix_time::ptime _t = boost::posix_time::second_clock::local_time();
- CURLcode error = curl_easy_perform(curl);
+ CURLcode error = CURL_LAST;
+ for(int i = 0; error && (i < 3); i++)
+ {
+ if(type == CURLPROXY_SOCKS5_HOSTNAME && i > 1)
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ error = curl_easy_perform(curl);
+ }
+
+ boost::posix_time::ptime _t2 = boost::posix_time::second_clock::local_time();
+
+ boost::posix_time::time_duration td = _t2 - _t;
- double t = time(0) - start;
+ double t = td.total_milliseconds();
curl_easy_cleanup(curl);
@@ -67,7 +78,7 @@ size_t speedtest::test(config::proxy_entry_base *p)
if(chunk.size)
{
if(t)
- speed = (double)chunk.size/t;
+ speed = (double)(chunk.size*1000)/t;
else
speed = chunk.size;
}