Fixes for pages not responding to Curl and process timeouts

This commit is contained in:
DarkFeather 2016-09-27 10:34:16 -05:00
parent ffb3bf8f73
commit d78809e410
2 changed files with 8 additions and 2 deletions

View File

@ -8,6 +8,9 @@ namespace AniNIX.Shared {
public static class ExecuteCommand { public static class ExecuteCommand {
// Allow anyone using this class to modify the timeout at will.
public static int TimeOut = 5000;
/// <summary> /// <summary>
/// This method allows a CSharp app to execute a command on the OS. /// This method allows a CSharp app to execute a command on the OS.
/// </summary> /// </summary>
@ -39,7 +42,10 @@ namespace AniNIX.Shared {
//Add input and read output. //Add input and read output.
proc.StandardInput.Write(input); proc.StandardInput.Write(input);
proc.StandardInput.Close(); proc.StandardInput.Close();
proc.WaitForExit(); proc.WaitForExit(TimeOut);
if (!proc.HasExited) {
proc.Kill();
}
if (proc.ExitCode != 0) { if (proc.ExitCode != 0) {
throw new Exception(String.Format("Failed to exit command with return code {0}",proc.ExitCode)); throw new Exception(String.Format("Failed to exit command with return code {0}",proc.ExitCode));
} }

View File

@ -20,7 +20,7 @@ namespace AniNIX.Shared {
/// <param name="pageURL"> the webpage whose title we should get</param> /// <param name="pageURL"> the webpage whose title we should get</param>
/// <returns> the webpage source </returns> /// <returns> the webpage source </returns>
public static string GetPage(String pageURL) { public static string GetPage(String pageURL) {
return ExecuteCommand.Run(String.Format("/usr/bin/curl -s {0}",pageURL)); return ExecuteCommand.Run(String.Format("/usr/bin/curl -s --max-time 5 {0}",pageURL));
} }
/// <summary> /// <summary>