mirror of https://github.com/2dust/v2rayN
Speed test via memory storage
parent
54adaffb92
commit
5907bf388c
|
@ -62,7 +62,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
void ws_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (UpdateCompleted != null)
|
if (UpdateCompleted != null)
|
||||||
|
@ -108,7 +108,7 @@ namespace v2rayN.Handler
|
||||||
if (e.Error == null
|
if (e.Error == null
|
||||||
|| Utils.IsNullOrEmpty(e.Error.ToString()))
|
|| Utils.IsNullOrEmpty(e.Error.ToString()))
|
||||||
{
|
{
|
||||||
|
((WebClientEx)sender).Dispose();
|
||||||
TimeSpan ts = (DateTime.Now - totalDatetime);
|
TimeSpan ts = (DateTime.Now - totalDatetime);
|
||||||
string speed = string.Format("{0} M/s", (totalBytesToReceive / ts.TotalMilliseconds / 1000).ToString("#0.0"));
|
string speed = string.Format("{0} M/s", (totalBytesToReceive / ts.TotalMilliseconds / 1000).ToString("#0.0"));
|
||||||
UpdateCompleted(this, new ResultEventArgs(true, speed.PadLeft(8, ' ')));
|
UpdateCompleted(this, new ResultEventArgs(true, speed.PadLeft(8, ' ')));
|
||||||
|
@ -189,5 +189,34 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WebClientEx DownloadDataAsync(string url, WebProxy webProxy, int downloadTimeout)
|
||||||
|
{
|
||||||
|
WebClientEx ws = new WebClientEx();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Utils.SetSecurityProtocol();
|
||||||
|
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, UIRes.I18N("Downloading")));
|
||||||
|
|
||||||
|
progressPercentage = -1;
|
||||||
|
totalBytesToReceive = 0;
|
||||||
|
|
||||||
|
DownloadTimeout = downloadTimeout;
|
||||||
|
if (webProxy != null)
|
||||||
|
{
|
||||||
|
ws.Proxy = webProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
|
||||||
|
ws.DownloadDataCompleted += ws_DownloadFileCompleted;
|
||||||
|
ws.DownloadDataAsync(new Uri(url));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utils.SaveLog(ex.Message, ex);
|
||||||
|
|
||||||
|
Error?.Invoke(this, new ErrorEventArgs(ex));
|
||||||
|
}
|
||||||
|
return ws;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,11 +220,12 @@ namespace v2rayN.Handler
|
||||||
int httpPort = _config.GetLocalPort("speedtest");
|
int httpPort = _config.GetLocalPort("speedtest");
|
||||||
|
|
||||||
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex);
|
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex);
|
||||||
var ws = downloadHandle2.DownloadFileAsync(url, webProxy, timeout - 2);
|
var ws = downloadHandle2.DownloadDataAsync(url, webProxy, timeout - 2);
|
||||||
|
|
||||||
Thread.Sleep(1000 * timeout);
|
Thread.Sleep(1000 * timeout);
|
||||||
|
|
||||||
ws.CancelAsync();
|
ws.CancelAsync();
|
||||||
|
ws.Dispose();
|
||||||
|
|
||||||
Thread.Sleep(1000 * 2);
|
Thread.Sleep(1000 * 2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue