diff options
author | Mike Kazantsev <mk.fraggod@gmail.com> | 2013-02-11 13:56:04 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2013-02-11 13:56:04 +0100 |
commit | 8e166ae8264a7c9f98e766c8635faa94cd075eb8 (patch) | |
tree | 10726e8e63315d87907a2530dd65f0b0f40208ba /protocols/skype/skyped.py | |
parent | 5a0ffa2be7f6e5354975abd6c17fffb43bb4d694 (diff) |
skype: cleanup of the send() code
Use socket.sendall(), as send() is not guaranteed to send all
the data passed (though it should generally work that way with
blocking sockets).
Use more robust, obvious and idiomatic loop conditions.
Cleanup redundant imports and variables.
Diffstat (limited to 'protocols/skype/skyped.py')
-rw-r--r-- | protocols/skype/skyped.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index 76368aba..57b2f9ce 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -123,35 +123,33 @@ def skype_idle_handler(skype): time.sleep(1) return True -def send(sock, txt): +def send(sock, txt, tries=10): global options - from time import sleep - count = 1 - done = False if hasgobject: - while (not done) and (count < 10): + for attempt in xrange(1, tries+1): try: - sock.send(txt) - done = True + sock.sendall(txt) except Exception, s: - count += 1 - dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) - sleep(1) - if not done: + dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, attempt)) + time.sleep(1) + else: + break + else: options.conn.close() else: - while (not done) and (count < 10) and options.conn: + for attempt in xrange(1, tries+1): + if not options.conn: break if wait_for_lock(options.lock, 3, 10, "socket send"): try: - if options.conn: sock.send(txt) + if options.conn: sock.sendall(txt) options.lock.release() - done = True except Exception, s: options.lock.release() - count += 1 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) - sleep(1) - if not done: + time.sleep(1) + else: + break + else: if options.conn: options.conn.close() options.conn = False |