mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-24 00:34:26 +08:00
Make cesu work
This commit is contained in:
parent
2c62dedd5c
commit
1d34248a1e
28
chsrc.c
28
chsrc.c
@ -68,44 +68,35 @@ to_human_readable_speed (double speed)
|
||||
double
|
||||
test_speed (char* url)
|
||||
{
|
||||
char* curl_cmd = xy_strjoin(4, "curl -qs -o ", xy_os_devnull, " -w \"%{http_code} %{speed_download}\" -m8 -A chsrc/" Chsrc_Version
|
||||
// 我们用 —L,因为Ruby China源会跳转到其他地方
|
||||
char* curl_cmd = xy_strjoin(4, "curl -qsL -o ", xy_os_devnull, " -w \"%{http_code} %{speed_download}\" -m8 -A chsrc/" Chsrc_Version
|
||||
" ", url);
|
||||
|
||||
// xy_info (xy_2strjoin("chsrc: 测速 ", url));
|
||||
puts(curl_cmd);
|
||||
system(curl_cmd);
|
||||
xy_info (xy_2strjoin("chsrc: 测速 ", url));
|
||||
|
||||
/*
|
||||
FILE* fp = popen(curl_cmd, "r");
|
||||
char buf[64] = {0};
|
||||
while(NULL!=fgets(buf, 64, fp));
|
||||
|
||||
puts("hello?");
|
||||
puts(buf);
|
||||
|
||||
// puts(buf);
|
||||
|
||||
// 如果尾部有换行,删除
|
||||
char* last_lf = strrchr(buf, '\n');
|
||||
if (last_lf) *last_lf = '\0';
|
||||
|
||||
char* split = strchr(buf, ' ');
|
||||
printf("diff = %d\n", split-buf);
|
||||
if (split) *split = '\0';
|
||||
puts(buf);
|
||||
puts(split+1);
|
||||
|
||||
// puts(buf); puts(split+1);
|
||||
int http_code = atoi(buf);
|
||||
double speed = atof(split+1);
|
||||
|
||||
printf("http_code = %d, speed = %f\n", http_code, speed);
|
||||
char* speedstr = to_human_readable_speed(speed);
|
||||
|
||||
if (200!=http_code) {
|
||||
xy_warn (xy_2strjoin("HTTP码 = ", buf));
|
||||
xy_warn (xy_strjoin(4, "chsrc: 速度 ", speedstr, " | HTTP码 " , http_code));
|
||||
} else {
|
||||
xy_info (xy_2strjoin("chsrc: 速度 ", speedstr));
|
||||
}
|
||||
puts(xy_2strjoin("速度 = ", speedstr));
|
||||
return speed;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -338,7 +329,6 @@ pl_ruby_cesu (char* option)
|
||||
source_info src = sources[i];
|
||||
const char* baseurl = src.url;
|
||||
char* testurl = xy_2strjoin(baseurl, "gems/nokogiri-1.15.0-java.gem");
|
||||
puts(testurl);
|
||||
double speed = test_speed (testurl);
|
||||
speeds[i] = speed;
|
||||
}
|
||||
|
6
chsrc.h
6
chsrc.h
@ -79,7 +79,7 @@ typedef struct {
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-29 更新
|
||||
* 2023-09-02 更新
|
||||
*
|
||||
* 速度已经过测试,目前北外最快,Ruby China 的源慢了一半
|
||||
*/
|
||||
@ -89,7 +89,9 @@ pl_ruby_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/rubygems/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rubygems/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/rubygems/"},
|
||||
{&RubyChina, "https://gems.ruby-china.com"},
|
||||
// Ruby China 给的链接是不带后缀 / 的,不知道是否带后缀会影响
|
||||
// 如有问题请报告
|
||||
{&RubyChina, "https://gems.ruby-china.com/"},
|
||||
},
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user