]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added pinging to keep connection open
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sun, 8 Aug 2010 00:25:43 +0000 (17:25 -0700)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sun, 8 Aug 2010 00:25:43 +0000 (17:25 -0700)
plugins/Irc/ircmanager.php

index b99c7b2fea3aa81a9647d4ea06b38b2c873bc624..bd6242a6a579ac55a87ebacd0a2a2e8a4b40b0da 100644 (file)
@@ -31,6 +31,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 class IrcManager extends ImManager {
     protected $conn = null;
+    protected $lastPing = null;
+
     protected $regchecks = array();
     protected $regchecksLookup = array();
 
@@ -63,6 +65,18 @@ class IrcManager extends ImManager {
         }
     }
 
+    /**
+     * Idle processing for io manager's execution loop.
+     * Send keepalive pings to server.
+     *
+     * @return void
+     */
+    public function idle($timeout = 0) {
+        if (empty($this->lastPing) || time() - $this->lastPing > 120) {
+            $this->send_ping();
+        }
+    }
+
     /**
      * Process IRC events that have come in over the wire.
      *
@@ -232,4 +246,14 @@ class IrcManager extends ImManager {
 
         return true;
     }
+
+    /**
+    * Sends a ping
+    *
+    * @return void
+    */
+    protected function send_ping() {
+        $this->lastPing = time();
+        $this->conn->send('PING', $this->lastPing);
+    }
 }