try to handle nightly debug port resets
authorChristian Weiske <cweiske@cweiske.de>
Sun, 21 Jun 2015 04:28:40 +0000 (06:28 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 21 Jun 2015 04:28:40 +0000 (06:28 +0200)
src/callnotifier/Exception/ConnectionReset.php [new file with mode: 0644]
src/callnotifier/Source/Remote.php

diff --git a/src/callnotifier/Exception/ConnectionReset.php b/src/callnotifier/Exception/ConnectionReset.php
new file mode 100644 (file)
index 0000000..a7bf139
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+namespace callnotifier;
+
+/**
+ * Since auerswald compact 3000 firmware 4.0N, the debug port is
+ * closed every night. We need to re-connect in this case
+ */
+class Exception_ConnectionReset extends \Exception
+{
+}
+?>
\ No newline at end of file
index 39b042c..4145c59 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);
     }