From d78809e4107380e958455f2bf65d6bd26c03b21d Mon Sep 17 00:00:00 2001 From: DarkFeather Date: Tue, 27 Sep 2016 10:34:16 -0500 Subject: [PATCH] Fixes for pages not responding to Curl and process timeouts --- CSharp/ExecuteCommand.csharp | 8 +++++++- CSharp/WebPageAPI.csharp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CSharp/ExecuteCommand.csharp b/CSharp/ExecuteCommand.csharp index ec5385f..2b474dc 100644 --- a/CSharp/ExecuteCommand.csharp +++ b/CSharp/ExecuteCommand.csharp @@ -7,6 +7,9 @@ using System.Collections.Generic; namespace AniNIX.Shared { public static class ExecuteCommand { + + // Allow anyone using this class to modify the timeout at will. + public static int TimeOut = 5000; /// /// This method allows a CSharp app to execute a command on the OS. @@ -39,7 +42,10 @@ namespace AniNIX.Shared { //Add input and read output. proc.StandardInput.Write(input); proc.StandardInput.Close(); - proc.WaitForExit(); + proc.WaitForExit(TimeOut); + if (!proc.HasExited) { + proc.Kill(); + } if (proc.ExitCode != 0) { throw new Exception(String.Format("Failed to exit command with return code {0}",proc.ExitCode)); } diff --git a/CSharp/WebPageAPI.csharp b/CSharp/WebPageAPI.csharp index b2fd906..980d508 100644 --- a/CSharp/WebPageAPI.csharp +++ b/CSharp/WebPageAPI.csharp @@ -20,7 +20,7 @@ namespace AniNIX.Shared { /// the webpage whose title we should get /// the webpage source 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)); } ///