Changeset 8e166ae for protocols


Ignore:
Timestamp:
2013-02-11T12:56:04Z (11 years ago)
Author:
Miklos Vajna <vmiklos@…>
Branches:
master
Children:
5a4f22e
Parents:
5a0ffa2
git-author:
Mike Kazantsev <mk.fraggod@…> (11-02-13 12:56:04)
git-committer:
Miklos Vajna <vmiklos@…> (11-02-13 12:56:04)
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/skype/skyped.py

    r5a0ffa2 r8e166ae  
    124124        return True
    125125
    126 def send(sock, txt):
    127         global options
    128         from time import sleep
    129         count = 1
    130         done = False
     126def send(sock, txt, tries=10):
     127        global options
    131128        if hasgobject:
    132                 while (not done) and (count < 10):
     129                for attempt in xrange(1, tries+1):
    133130                        try:
    134                                 sock.send(txt)
    135                                 done = True
     131                                sock.sendall(txt)
    136132                        except Exception, s:
    137                                 count += 1
    138                                 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count))
    139                                 sleep(1)
    140                 if not done:
     133                                dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, attempt))
     134                                time.sleep(1)
     135                        else:
     136                                break
     137                else:
    141138                        options.conn.close()
    142139        else:
    143                 while (not done) and (count < 10) and options.conn:
     140                for attempt in xrange(1, tries+1):
     141                        if not options.conn: break
    144142                        if wait_for_lock(options.lock, 3, 10, "socket send"):
    145143                                try:
    146                                          if options.conn: sock.send(txt)
     144                                         if options.conn: sock.sendall(txt)
    147145                                         options.lock.release()
    148                                          done = True
    149146                                except Exception, s:
    150147                                        options.lock.release()
    151                                         count += 1
    152148                                        dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count))
    153                                         sleep(1)
    154                 if not done:
     149                                        time.sleep(1)
     150                                else:
     151                                        break
     152                else:
    155153                        if options.conn:
    156154                                options.conn.close()
Note: See TracChangeset for help on using the changeset viewer.