我试图编写一个简单的多线程vlang应用程序调用'http://www.google.com'和'http://www.bing.com'各50次,并计算响应大小。但我得到dial_tcp failed
多个请求:
代码如下:
module main
import net.http
import sync.pool
struct IResult {
u string
c int
}
fn sprocess(pp &pool.PoolProcessor, idx int, wid int) &IResult {
item := pp.get_item<string>(idx)
resp := http.get(item) or {
println('Err [ for $item ]: $err.msg')
return &IResult{
item,
0
}
}
return &IResult{
item,
utf8_str_len(resp.text)
}
}
fn main() {
mut pp := pool.new_pool_processor(callback: sprocess)
pp.work_on_items(['http://www.google.com', 'http://www.bing.com'].repeat(50))
for x in pp.get_results<IResult>() {
println('$x.u len = $x.c')
}
}
我用最新的主(1b9eef7
)尝试了相同的代码,它在run
和直接调用二进制文件(./main
)时都工作得很好。
使用libssl-dev
在系统上存在。考虑升级V并使用libssl-dev
:
$ v run main.v
http://www.google.com len = 14969
http://www.bing.com len = 80681
http://www.google.com len = 14982
http://www.bing.com len = 80682
http://www.google.com len = 14903
http://www.bing.com len = 80682
http://www.google.com len = 14999
http://www.bing.com len = 80682
http://www.google.com len = 14938
http://www.bing.com len = 80682
http://www.google.com len = 14895
http://www.bing.com len = 80682
http://www.google.com len = 14985
http://www.bing.com len = 80682
http://www.google.com len = 14996
http://www.bing.com len = 80682
http://www.google.com len = 14982
http://www.bing.com len = 80682
http://www.google.com len = 14983
http://www.bing.com len = 80682
http://www.google.com len = 14998
http://www.bing.com len = 80681
http://www.google.com len = 14932
http://www.bing.com len = 80682
http://www.google.com len = 14943
http://www.bing.com len = 80682
http://www.google.com len = 15005
http://www.bing.com len = 80682
http://www.google.com len = 15017
http://www.bing.com len = 80682
http://www.google.com len = 14966
http://www.bing.com len = 80682
http://www.google.com len = 14990
http://www.bing.com len = 80682
http://www.google.com len = 14950
http://www.bing.com len = 81099
http://www.google.com len = 14977
http://www.bing.com len = 80682
http://www.google.com len = 14976
http://www.bing.com len = 80681
http://www.google.com len = 14924
http://www.bing.com len = 80682
http://www.google.com len = 14992
http://www.bing.com len = 80682
http://www.google.com len = 14990
http://www.bing.com len = 80682
http://www.google.com len = 15026
http://www.bing.com len = 80682
http://www.google.com len = 15037
http://www.bing.com len = 80682
http://www.google.com len = 14967
http://www.bing.com len = 80682
http://www.google.com len = 14947
http://www.bing.com len = 80682
http://www.google.com len = 14969
http://www.bing.com len = 80682
http://www.google.com len = 14965
http://www.bing.com len = 80682
http://www.google.com len = 14934
http://www.bing.com len = 80682
http://www.google.com len = 14937
http://www.bing.com len = 80682
http://www.google.com len = 15001
http://www.bing.com len = 80682
http://www.google.com len = 14984
http://www.bing.com len = 80682
http://www.google.com len = 15001
http://www.bing.com len = 80682
http://www.google.com len = 14969
http://www.bing.com len = 80682
http://www.google.com len = 14947
http://www.bing.com len = 80681
http://www.google.com len = 14976
http://www.bing.com len = 80682
http://www.google.com len = 14970
http://www.bing.com len = 80682
http://www.google.com len = 14949
http://www.bing.com len = 80682
http://www.google.com len = 14944
http://www.bing.com len = 80682
http://www.google.com len = 14974
http://www.bing.com len = 80682
http://www.google.com len = 14989
http://www.bing.com len = 80682
http://www.google.com len = 14985
http://www.bing.com len = 80682
http://www.google.com len = 14964
http://www.bing.com len = 80682
http://www.google.com len = 14965
http://www.bing.com len = 80682
http://www.google.com len = 14902
http://www.bing.com len = 80681
http://www.google.com len = 15011
http://www.bing.com len = 80682
http://www.google.com len = 14904
http://www.bing.com len = 80681
http://www.google.com len = 15001
http://www.bing.com len = 80682
http://www.google.com len = 14948
http://www.bing.com len = 80682