Skip to content

Commit

Permalink
Make resources download timeout after 20 seconds instead of 2 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 9, 2017
1 parent 9202833 commit 076151d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
13 changes: 13 additions & 0 deletions fCraft/Network/HttpUtil.cs
Expand Up @@ -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);
}
}
}
}
17 changes: 11 additions & 6 deletions fCraft/System/Server.cs
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 076151d

Please sign in to comment.