]> git.mxchange.org Git - flightgear.git/commitdiff
First attempt to handle the nasty socket timeout
authorTorsten Dreyer <torsten@t3r.de>
Wed, 25 May 2016 14:19:36 +0000 (16:19 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:35 +0000 (23:27 +0200)
Retry once if a http get fails

scripts/python/terrasync.py

index aeb19566509e30431ebb43feb50dbb69d28f4906..6798a1edcaeb26cec674def2f2b523b4ee1ab189 100755 (executable)
@@ -43,24 +43,24 @@ class HTTPGetter:
         self.httpConnection = HTTPConnection(self.parsedBaseUrl.netloc,80, True)
         self.httpRequestHeaders = headers = {'Host':self.parsedBaseUrl.netloc,'Content-Length':0,'Connection':'Keep-Alive','User-Agent':'FlightGear terrasync.py'}
 
-    def get(self, httpGetCallback):
-
-        #self.requests.append(httpGetCallback)
+    def doGet(self, httpGetCallback):
         conn = self.httpConnection
         request = httpGetCallback
-        conn.request("GET", self.parsedBaseUrl.path + request.src, None, self.httpRequestHeaders)
+        self.httpConnection.request("GET", self.parsedBaseUrl.path + request.src, None, self.httpRequestHeaders)
+        httpGetCallback.result = self.httpConnection.getresponse()
+        httpGetCallback.callback()
+
+    def get(self, httpGetCallback):
+
         try:
-            httpGetCallback.result = conn.getresponse()
+            self.doGet(httpGetCallback)
         except:
             # try to reconnect once
             #print("reconnect")
-            conn.close()
-            conn.connect()
-            conn.request("GET", self.parsedBaseUrl.path + request.src, None, self.httpRequestHeaders)
-            httpGetCallback.result = conn.getresponse()
+            self.httpConnection.close()
+            self.httpConnection.connect()
+            self.doGet(httpGetCallback)
 
-        httpGetCallback.callback()
-        #self.requests.remove(httpGetCallback)
 
 #################################################################################################################################
 class DirIndex: