Changeset d45adcf
- Timestamp:
- 2010-12-24T12:21:16Z (14 years ago)
- Branches:
- master
- Children:
- 1130561
- Parents:
- 9c51166
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/skyped.py
r9c51166 rd45adcf 34 34 import ssl 35 35 import select 36 import threading 36 37 37 38 __version__ = "0.1.1" … … 51 52 52 53 sys.excepthook = eh 54 55 def wait_for_lock(lock, timeout_to_print, timeout, msg): 56 start = time.time() 57 locked = lock.acquire(0) 58 while not(locked): 59 time.sleep(0.5) 60 if timeout_to_print and (time.time() - timeout_to_print > start): 61 dprint("%s: Waited %f seconds" % \ 62 (msg, time.time() - start)) 63 timeout_to_print = False 64 if timeout and (time.time() - timeout > start): 65 dprint("%s: Waited %f seconds, giving up" % \ 66 (msg, time.time() - start)) 67 return False 68 locked = lock.acquire(0) 69 return True 53 70 54 71 def input_handler(fd): … … 61 78 return True 62 79 else: 63 try: 64 input = fd.recv(1024) 65 except Exception, s: 66 dprint("Warning, receiving 1024 bytes failed (%s)." % s) 67 fd.close() 68 options.conn = False 69 return False 70 for i in input.split("\n"): 71 skype.send(i.strip()) 80 if wait_for_lock(options.lock, 3, 10, "input_handler"): 81 try: 82 input = fd.recv(1024) 83 options.lock.release() 84 except Exception, s: 85 dprint("Warning, receiving 1024 bytes failed (%s)." % s) 86 fd.close() 87 options.conn = False 88 options.lock.release() 89 return False 90 for i in input.split("\n"): 91 skype.send(i.strip()) 72 92 return True 73 93 … … 85 105 done = False 86 106 while (not done) and (count < 10): 87 try: 88 sock.send(txt) 89 done = True 90 except Exception, s: 91 count += 1 92 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) 93 time.sleep(1) 107 if wait_for_lock(options.lock, 3, 10, "socket send"): 108 try: 109 sock.send(txt) 110 options.lock.release() 111 done = True 112 except Exception, s: 113 options.lock.release() 114 count += 1 115 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) 116 time.sleep(1) 94 117 if not done: 95 118 if options.conn: options.conn.close() … … 123 146 def listener(sock, skype): 124 147 global options 148 if not(wait_for_lock(options.lock, 3, 10, "listener")): return False 125 149 rawsock, addr = sock.accept() 126 150 options.conn = ssl.wrap_socket(rawsock, … … 133 157 options.conn.handshake() 134 158 except Exception: 159 options.lock.release() 135 160 dprint("Warning, handshake failed, closing connection.") 136 161 return False … … 147 172 options.conn.close() 148 173 options.conn = False 174 options.lock.release() 149 175 return False 150 176 if ret == 2: 151 177 dprint("Username and password OK.") 152 178 options.conn.send("PASSWORD OK\n") 179 options.lock.release() 153 180 serverloop(options, skype) 154 181 return True … … 158 185 options.conn.close() 159 186 options.conn = False 187 options.lock.release() 160 188 return False 161 189 … … 384 412 while 1: 385 413 options.conn = False 414 options.lock = threading.Lock() 386 415 server(options.host, options.port, skype)
Note: See TracChangeset
for help on using the changeset viewer.