Make cesu work

This commit is contained in:
Aoran Zeng 2023-09-02 22:23:49 +08:00
parent 2c62dedd5c
commit 1d34248a1e
3 changed files with 14 additions and 22 deletions

28
chsrc.c
View File

@ -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;
}

View File

@ -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/"},
},

View File

@ -176,7 +176,7 @@ xy_2strjoin (const char* str1, const char* str2)
static char*
xy_strjoin (unsigned int count, ...)
{
size_t al_fixed = 128;
size_t al_fixed = 256;
char* ret = calloc(1, al_fixed);
// 已分配次数
int al_times = 1;