From ce6c54926377f033faded160aeb12b740c04e36f Mon Sep 17 00:00:00 2001 From: Jacob Peddicord Date: Mon, 5 Apr 2010 08:41:28 -0400 Subject: [PATCH] try to recover from a failed send --- highlightxmpp.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/highlightxmpp.py b/highlightxmpp.py index 37d33b7..657f97d 100644 --- a/highlightxmpp.py +++ b/highlightxmpp.py @@ -1,6 +1,6 @@ # HighlightXMPP for IRC. Requires WeeChat >= 0.3.0. # -# Copyright (c) 2009 Jacob Peddicord +# Copyright (c) 2009-2010 Jacob Peddicord # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,13 +25,14 @@ # JID messages are sent *to* (if not set, defaults to the same jid): # /set plugins.var.python.highlightxmpp.jid myid@jabber.org +from time import sleep import weechat as w import xmpp info = ( 'highlightxmpp', 'Jacob Peddicord ', - '0.1', + '0.2', 'GPL3', "Relay highlighted & private IRC messages over XMPP (Jabber)", '', @@ -66,7 +67,7 @@ def connect_xmpp(): return False return True -def send_xmpp(data, signal, msg): +def send_xmpp(data, signal, msg, trial=1): global client # connect to xmpp if we need to if not connect_xmpp(): @@ -77,7 +78,17 @@ def send_xmpp(data, signal, msg): jid_to = w.config_get_plugin('jid') # send the message msg = xmpp.protocol.Message(jid_to, msg) - client.send(msg) + try: + client.send(msg) + except IOError: + # every now and then the connection will still exist but a send will + # fail. catch that here and try to reconnect. isConnected() should + # start to realize that once this exception is triggered. + if trial > 3: + w.prnt('', "Could send to XMPP server.") + else: + w.prnt('', "Lost connection to XMPP server. Trying to send again... (trial %d)" % trial + 1) + send_xmpp(data, signal, msg, trial + 1) return w.WEECHAT_RC_OK # register with weechat