[icinga-checkins] icinga.org: icingaweb2/feature/livestatus-playground-4787: Livestatus\Connection: check resource on disconnect

git at icinga.org git at icinga.org
Sun Nov 16 18:04:25 CET 2014


Module: icingaweb2
Branch: feature/livestatus-playground-4787
Commit: d368df8211d688d9356a3b2597c52fc16cf98231
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=d368df8211d688d9356a3b2597c52fc16cf98231

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sun Nov 16 18:01:07 2014 +0100

Livestatus\Connection: check resource on disconnect

---

 library/Icinga/Protocol/Livestatus/Connection.php |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/library/Icinga/Protocol/Livestatus/Connection.php b/library/Icinga/Protocol/Livestatus/Connection.php
index ded487e..c24b8ed 100644
--- a/library/Icinga/Protocol/Livestatus/Connection.php
+++ b/library/Icinga/Protocol/Livestatus/Connection.php
@@ -407,11 +407,21 @@ if ($col > $size - 1) return $res;
         return $this;
     }
 
+    /**
+     * Disconnect in case we are connected to a Livestatus socket
+     *
+     * @return self
+     */
     public function disconnect()
     {
-        if ($this->connection) {
+        if (is_resource($this->connection)
+            && get_resource_type($this->connection) === 'Socket')
+        {
+            Benchmark::measure('Disconnecting livestatus...');
             socket_close($this->connection);
+            Benchmark::measure('...socket closed');
         }
+        return $this;
     }
 
     public function __destruct()



More information about the icinga-checkins mailing list