Skip to content
Permalink
Browse files

Make resources download timeout after 20 seconds instead of 2 minutes

  • Loading branch information...
UnknownShadow200 committed Jul 9, 2017
1 parent 9202833 commit 076151da145a4f33b2f12373418dd7465b741b5f
Showing with 24 additions and 6 deletions.
  1. +13 −0 fCraft/Network/HttpUtil.cs
  2. +11 −6 fCraft/System/Server.cs
@@ -68,6 +68,19 @@ public static class HttpUtil {
}
}
return req;
}

public static WebClient CreateWebClient(TimeSpan timeout) {
return new CustomWebClient(timeout);
}

class CustomWebClient : WebClient {
readonly TimeSpan timeout;
public CustomWebClient(TimeSpan timeout) { this.timeout = timeout; }

protected override WebRequest GetWebRequest(Uri address) {
return CreateRequest(address, timeout);
}
}
}
}
@@ -481,13 +481,18 @@ public static partial class Server {
if (File.Exists(file)) return;

try {
new WebClient().DownloadFile(url, file);
} catch (WebException ex) {
WebResponse resp = ex.Response;
if (resp != null) resp.Close();
TimeSpan timeout = TimeSpan.FromSeconds(20);
using (WebClient c = HttpUtil.CreateWebClient(timeout)) {
c.DownloadFile(url, file);
}
} catch (Exception ex) {
WebException webEx = ex as WebException;
if (webEx != null) {
WebResponse resp = webEx.Response;
if (resp != null) resp.Close();
}

Logger.Log(LogType.Warning, "Error downloading resource {0}: {1}",
file, ex);
Logger.Log(LogType.Warning, "Error downloading resource {0}: {1}", file, ex);
}
}

0 comments on commit 076151d

Please sign in to comment.
You can’t perform that action at this time.