X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fxmppqueuehandler.php;h=f28fc9088c47b1449b91a0575f4656e43b3abf2e;hb=e150d920a53cbafaf6ff3f6397fa40f8cc0e526e;hp=9b1a6989e2d1f25fae2698dc9cd833d3edba8178;hpb=d7611009b11c489abbc7c52d51ec859fd9fa5600;p=quix0rs-gnu-social.git diff --git a/lib/xmppqueuehandler.php b/lib/xmppqueuehandler.php index 9b1a6989e2..f28fc9088c 100644 --- a/lib/xmppqueuehandler.php +++ b/lib/xmppqueuehandler.php @@ -1,7 +1,7 @@ . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/queuehandler.php'); +define('PING_INTERVAL', 120); + /** * Common superclass for all XMPP-using queue handlers. They all need to * service their message queues on idle, and forward any incoming messages @@ -31,18 +33,25 @@ require_once(INSTALLDIR.'/lib/queuehandler.php'); class XmppQueueHandler extends QueueHandler { var $pingid = 0; + var $lastping = null; function start() { # Low priority; we don't want to receive messages + $this->log(LOG_INFO, "INITIALIZE"); $this->conn = jabber_connect($this->_id.$this->transport()); - if ($this->conn) { - $this->conn->addEventHandler('message', 'forward_message', $this); - $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); - $this->conn->setReconnectTimeout(600); - jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', -1); + + if (empty($this->conn)) { + $this->log(LOG_ERR, "Couldn't connect to server."); + return false; } + + $this->conn->addEventHandler('message', 'forward_message', $this); + $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); + $this->conn->setReconnectTimeout(600); + jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', -1); + return !is_null($this->conn); } @@ -53,6 +62,8 @@ class XmppQueueHandler extends QueueHandler function handle_reconnect(&$pl) { + $this->log(LOG_NOTICE, 'reconnected'); + $this->conn->processUntil('session_start'); $this->conn->presence(null, 'available', null, 'available', -1); } @@ -64,7 +75,11 @@ class XmppQueueHandler extends QueueHandler if ($this->conn) { $this->log(LOG_DEBUG, "Servicing the XMPP queue."); $this->conn->processTime($timeout); - $this->sendPing(); + $now = time(); + if (empty($this->lastping) || $now - $this->lastping > PING_INTERVAL) { + $this->sendPing(); + $this->lastping = $now; + } } } catch (XMPPHP_Exception $e) { $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); @@ -119,4 +134,9 @@ class XmppQueueHandler extends QueueHandler return jabber_daemon_address() . '/' . common_config('xmpp','resource') . 'daemon'; } } + + function getSockets() + { + return array($this->conn->getSocket()); + } }