Ticket #966: skyped_close_connection_on_send_error.patch
File skyped_close_connection_on_send_error.patch, 2.2 KB (added by , at 2013-01-28T02:52:11Z) |
---|
-
skyped
a b 124 124 time.sleep(1) 125 125 return True 126 126 127 def send( sock, txt):127 def send(txt, tries=10): 128 128 global options 129 from time import sleep130 count = 1131 done = False132 129 if hasgobject: 133 while (not done) and (count < 10):130 if not options.conn: return 134 131 try: 135 sock.send(txt) 136 done = True 132 options.conn.sendall(txt) 137 133 except Exception, s: 138 count += 1 139 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) 140 sleep(1) 141 if not done: 134 dprint("Warning, sending '%s' failed (%s)." % (txt, s)) 142 135 options.conn.close() 136 options.conn = False 143 137 else: 144 while (not done) and (count < 10) and options.conn: 138 for attempt in xrange(1, tries+1): 139 if not options.conn: break 145 140 if wait_for_lock(options.lock, 3, 10, "socket send"): 146 141 try: 147 if options.conn: sock.send(txt)142 if options.conn: options.conn.sendall(txt) 148 143 options.lock.release() 149 done = True150 144 except Exception, s: 151 145 options.lock.release() 152 count += 1153 146 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) 154 sleep(1) 155 if not done: 147 time.sleep(1) 148 else: 149 break 150 else: 156 151 if options.conn: 157 152 options.conn.close() 158 153 options.conn = False … … 164 159 if options.conn: 165 160 try: 166 161 e = "PING" 167 done = send( options.conn,"%s\n" % e)162 done = send("%s\n" % e) 168 163 except Exception, s: 169 164 dprint("Warning, sending '%s' failed (%s)." % (e, s)) 170 165 if hasgobject: … … 235 230 return False 236 231 if ret == 2: 237 232 dprint("Username and password OK.") 238 options.conn.send("PASSWORD OK\n")233 send("PASSWORD OK\n") 239 234 if hasgobject: 240 235 gobject.io_add_watch(options.conn, gobject.IO_IN, input_handler) 241 236 else: … … 244 239 return True 245 240 else: 246 241 dprint("Username and/or password WRONG.") 247 options.conn.send("PASSWORD KO\n")242 send("PASSWORD KO\n") 248 243 if not hasgobject: 249 244 options.conn.close() 250 245 options.conn = False … … 308 303 if options.conn: 309 304 dprint('<< ' + e) 310 305 try: 311 send( options.conn,e + "\n")306 send(e + "\n") 312 307 except Exception, s: 313 308 dprint("Warning, sending '%s' failed (%s)." % (e, s)) 314 309 if options.conn: options.conn.close()