Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce default timeout to 10 seconds #575

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private static int GetCnCNetPlayerCount()
{
// Don't fetch the player count if it is explicitly disabled
// For example, the official CnCNet server might be unavailable/unstable in a country with Internet censorship,
// which causes lags in the splash screen. In the worst case, say if packets are dropped, it waits until timeouts --- 30 seconds
// which causes lags in the splash screen. In the worst case, say if packets are dropped, it waits until timeouts
if (string.IsNullOrWhiteSpace(ClientConfiguration.Instance.CnCNetPlayerCountURL))
return -1;

WebClient client = new WebClient();
WebClient client = new ExtendedWebClient();
Stream data = client.OpenRead(ClientConfiguration.Instance.CnCNetPlayerCountURL);

string info = string.Empty;
Expand Down
2 changes: 2 additions & 0 deletions DXMainClient/Domain/Multiplayer/CnCNet/ExtendedWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace DTAClient.Domain.Multiplayer.CnCNet
/// </summary>
class ExtendedWebClient : WebClient
{
public ExtendedWebClient() : this(timeout: 10000) { }

public ExtendedWebClient(int timeout)
{
this.timeout = timeout;
Expand Down
27 changes: 5 additions & 22 deletions DXMainClient/Domain/Multiplayer/CnCNet/MapSharer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static class MapSharer

private static readonly object locker = new object();

private const int DOWNLOAD_TIMEOUT = 100000; // In milliseconds
private const int UPLOAD_TIMEOUT = 100000; // In milliseconds

/// <summary>
/// Adds a map into the CnCNet map upload queue.
/// </summary>
Expand Down Expand Up @@ -211,6 +214,7 @@ private static void CopyStream(Stream input, Stream output)
private static byte[] UploadFiles(string address, List<FileToUpload> files, NameValueCollection values)
{
WebRequest request = WebRequest.Create(address);
request.Timeout = UPLOAD_TIMEOUT;
request.Method = "POST";
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", NumberFormatInfo.InvariantInfo);
request.ContentType = "multipart/form-data; boundary=" + boundary;
Expand Down Expand Up @@ -382,11 +386,8 @@ private static string DownloadMain(string sha1, string myGame, string mapName, o
destinationFile.Delete();
newFile.Delete();

using (TWebClient webClient = new TWebClient())
using (WebClient webClient = new ExtendedWebClient(DOWNLOAD_TIMEOUT))
{
// TODO enable proxy support for some users
webClient.Proxy = null;

if (string.IsNullOrWhiteSpace(ClientConfiguration.Instance.CnCNetMapDBDownloadURL))
{
success = false;
Expand Down Expand Up @@ -456,23 +457,5 @@ public FileToUpload()
public string ContentType { get; set; }
public Stream Stream { get; set; }
}

class TWebClient : WebClient
{
private int Timeout = 10000;

public TWebClient()
{
// TODO enable proxy support for some users
this.Proxy = null;
}

protected override WebRequest GetWebRequest(Uri address)
{
var webRequest = base.GetWebRequest(address);
webRequest.Timeout = Timeout;
return webRequest;
}
}
}
}
2 changes: 1 addition & 1 deletion DXMainClient/Domain/Multiplayer/CnCNet/TunnelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private Task PingCurrentTunnelAsync(bool checkTunnelList = false)

private byte[] GetRawTunnelDataOnline()
{
WebClient client = new WebClient();
WebClient client = new ExtendedWebClient();
return client.DownloadData(MainClientConstants.CNCNET_TUNNEL_LIST_URL);
}

Expand Down
Loading