mirror of
https://github.com/RubyMetric/chsrc
synced 2025-08-08 12:09:31 +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
|
double
|
||||||
test_speed (char* url)
|
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);
|
" ", url);
|
||||||
|
|
||||||
// xy_info (xy_2strjoin("chsrc: 测速 ", url));
|
xy_info (xy_2strjoin("chsrc: 测速 ", url));
|
||||||
puts(curl_cmd);
|
|
||||||
system(curl_cmd);
|
|
||||||
|
|
||||||
/*
|
|
||||||
FILE* fp = popen(curl_cmd, "r");
|
FILE* fp = popen(curl_cmd, "r");
|
||||||
char buf[64] = {0};
|
char buf[64] = {0};
|
||||||
while(NULL!=fgets(buf, 64, fp));
|
while(NULL!=fgets(buf, 64, fp));
|
||||||
|
// puts(buf);
|
||||||
puts("hello?");
|
|
||||||
puts(buf);
|
|
||||||
|
|
||||||
|
|
||||||
// 如果尾部有换行,删除
|
// 如果尾部有换行,删除
|
||||||
char* last_lf = strrchr(buf, '\n');
|
char* last_lf = strrchr(buf, '\n');
|
||||||
if (last_lf) *last_lf = '\0';
|
if (last_lf) *last_lf = '\0';
|
||||||
|
|
||||||
char* split = strchr(buf, ' ');
|
char* split = strchr(buf, ' ');
|
||||||
printf("diff = %d\n", split-buf);
|
|
||||||
if (split) *split = '\0';
|
if (split) *split = '\0';
|
||||||
puts(buf);
|
|
||||||
puts(split+1);
|
// puts(buf); puts(split+1);
|
||||||
int http_code = atoi(buf);
|
int http_code = atoi(buf);
|
||||||
double speed = atof(split+1);
|
double speed = atof(split+1);
|
||||||
|
|
||||||
printf("http_code = %d, speed = %f\n", http_code, speed);
|
|
||||||
char* speedstr = to_human_readable_speed(speed);
|
char* speedstr = to_human_readable_speed(speed);
|
||||||
|
|
||||||
if (200!=http_code) {
|
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 speed;
|
||||||
*/
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -338,7 +329,6 @@ pl_ruby_cesu (char* option)
|
|||||||
source_info src = sources[i];
|
source_info src = sources[i];
|
||||||
const char* baseurl = src.url;
|
const char* baseurl = src.url;
|
||||||
char* testurl = xy_2strjoin(baseurl, "gems/nokogiri-1.15.0-java.gem");
|
char* testurl = xy_2strjoin(baseurl, "gems/nokogiri-1.15.0-java.gem");
|
||||||
puts(testurl);
|
|
||||||
double speed = test_speed (testurl);
|
double speed = test_speed (testurl);
|
||||||
speeds[i] = speed;
|
speeds[i] = speed;
|
||||||
}
|
}
|
||||||
|
6
chsrc.h
6
chsrc.h
@ -79,7 +79,7 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2023-08-29 更新
|
* 2023-09-02 更新
|
||||||
*
|
*
|
||||||
* 速度已经过测试,目前北外最快,Ruby China 的源慢了一半
|
* 速度已经过测试,目前北外最快,Ruby China 的源慢了一半
|
||||||
*/
|
*/
|
||||||
@ -89,7 +89,9 @@ pl_ruby_sources[] = {
|
|||||||
{&Ali, "https://mirrors.aliyun.com/rubygems/"},
|
{&Ali, "https://mirrors.aliyun.com/rubygems/"},
|
||||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rubygems/"},
|
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rubygems/"},
|
||||||
{&Tencent, "https://mirrors.tencent.com/rubygems/"},
|
{&Tencent, "https://mirrors.tencent.com/rubygems/"},
|
||||||
{&RubyChina, "https://gems.ruby-china.com"},
|
// Ruby China 给的链接是不带后缀 / 的,不知道是否带后缀会影响
|
||||||
|
// 如有问题请报告
|
||||||
|
{&RubyChina, "https://gems.ruby-china.com/"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
2
helper.h
2
helper.h
@ -176,7 +176,7 @@ xy_2strjoin (const char* str1, const char* str2)
|
|||||||
static char*
|
static char*
|
||||||
xy_strjoin (unsigned int count, ...)
|
xy_strjoin (unsigned int count, ...)
|
||||||
{
|
{
|
||||||
size_t al_fixed = 128;
|
size_t al_fixed = 256;
|
||||||
char* ret = calloc(1, al_fixed);
|
char* ret = calloc(1, al_fixed);
|
||||||
// 已分配次数
|
// 已分配次数
|
||||||
int al_times = 1;
|
int al_times = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user