try to handle nightly debug port resets
[auerswald-callnotifier.git] / src / callnotifier / Source / Remote.php
index 39b042c966de7a3f1958ad5b4c80026e3c2e4e1f..4145c59e8b7041469746d024ad09d71a03897198 100644 (file)
@@ -13,9 +13,16 @@ class Source_Remote
 
     public function run()
     {
-        $this->connect($this->config->host, $this->config->port);
-        $this->init();
-        $this->loop();
+        do {
+            try {
+                $tryAgain = false;
+                $this->connect($this->config->host, $this->config->port);
+                $this->init();
+                $this->loop();
+            } catch (\Exception_ConnectionReset $e) {
+                $tryAgain = true;
+            }
+        } while ($tryAgain);
         $this->disconnect();
     }
 
@@ -64,6 +71,11 @@ class Source_Remote
     function read_response()
     {
         $res = socket_read($this->socket, 2048, PHP_NORMAL_READ);
+        if ($res === false) {
+            //handle "Connection reset by peer" that appears nightly since
+            // version 4.0N
+            throw new Exception_ConnectionReset();
+        }
         return substr($res, 2, -1);
     }