diff options
author | mrDoctorWho <mrdoctorwho@gmail.com> | 2014-01-09 21:51:38 +0400 |
---|---|---|
committer | mrDoctorWho <mrdoctorwho@gmail.com> | 2014-01-09 21:51:38 +0400 |
commit | 513c491c318e311c2688ce143e6da0ccb13f2dec (patch) | |
tree | cd006840fd2fb29cfedf0b043af731fe648dd832 | |
parent | 064b2195afabefe133f9dd202037011f9d0367e4 (diff) |
fix for ejabberd queue: clients disconnects when sent many stanzas
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | xmpp/transports.py | 25 |
2 files changed, 15 insertions, 12 deletions
@@ -1,4 +1,4 @@ xmpppy ====== -Just another fork of xmpppy library. +Just another fork of xmpppy library. Provides full compability with standart xmpppy but also have a lot of security fixes.
\ No newline at end of file diff --git a/xmpp/transports.py b/xmpp/transports.py index 71e1fb3..210fb36 100644 --- a/xmpp/transports.py +++ b/xmpp/transports.py @@ -206,7 +206,7 @@ class TCPsocket(PlugIn): raise IOError("Disconnected!") return data - def send(self, data): + def send(self, data, timeout=0.002): """ Writes raw outgoing data. Blocks until done. If supplied data is unicode string, encodes it to utf-8 before send. @@ -215,17 +215,20 @@ class TCPsocket(PlugIn): data = data.encode("utf-8") elif not isinstance(data, str): data = ustr(data).encode("utf-8") - try: - self._send(data) - except Exception: - self.DEBUG("Socket error while sending data.", "error") - self._owner.disconnected() + while not select((), [self._sock], (), timeout)[1]: + pass else: - if not data.strip(): - data = repr(data) - self.DEBUG(data, "sent") - if hasattr(self._owner, "Dispatcher"): - self._owner.Dispatcher.Event("", DATA_SENT, data) + try: + self._send(data) + except Exception: + self.DEBUG("Socket error while sending data.", "error") + self._owner.disconnected() + else: + if not data.strip(): + data = repr(data) + self.DEBUG(data, "sent") + if hasattr(self._owner, "Dispatcher"): + self._owner.Dispatcher.Event("", DATA_SENT, data) def pending_data(self, timeout=0): """ |