From 34594e40e83ec7b0065c9b3e0ea4f47789cf3fa1 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 28 Jul 2011 22:55:54 +0200 Subject: [PATCH] Move method and cleanup docstrings --- mopidy/utils/network.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mopidy/utils/network.py b/mopidy/utils/network.py index 84fe49bd..5079fe7c 100644 --- a/mopidy/utils/network.py +++ b/mopidy/utils/network.py @@ -162,13 +162,24 @@ class Connection(object): pass def queue_send(self, data): - """Send data to client exactly as is.""" + """Try to send data to client exactly as is and queue rest.""" self.send_lock.acquire(True) self.send_buffer = self.send(self.send_buffer + data) self.send_lock.release() if self.send_buffer: self.enable_send() + def send(self, data): + """Send data to client, return any unsent data.""" + try: + sent = self.sock.send(data) + return data[sent:] + except socket.error as e: + if e.errno in (errno.EWOULDBLOCK, errno.EINTR): + return data + self.stop(u'Unexpected client error: %s' % e) + return '' + def enable_timeout(self): """Reactivate timeout mechanism.""" if self.timeout <= 0: @@ -262,16 +273,6 @@ class Connection(object): return True - def send(self, data): - try: - sent = self.sock.send(data) - return data[sent:] - except socket.error as e: - if e.errno in (errno.EWOULDBLOCK, errno.EINTR): - return data - self.stop(u'Unexpected client error: %s' % e) - return '' - def timeout_callback(self): self.stop(u'Client timeout out after %s seconds' % self.timeout) return False