Changeset 83

Show
Ignore:
Timestamp:
04/08/05 15:39:39 (7 years ago)
Author:
mj
Message:

Refactor IDE connection callback; make it a module-level function.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • WingDBG/trunk/WingDBG/WingDBG.py

    r80 r83  
    7070         
    7171class IDEConnectionTimeOut(Exception): 
    72     """Flag exception thrown on IDE conn timeout."""     
     72    """Flag exception thrown on IDE conn timeout.""" 
     73     
     74 
     75def connectToIDECallback(status): 
     76    """Callback to open IDE connection on debug server thread""" 
     77    try: 
     78        if gHttpServer.debugger is not None: 
     79            # temporary try: except: wrapper to work around exception 
     80            # detection in the debugger 
     81            try: 
     82                # Without the following line, the debugger-to-IDE  
     83                # auto-connect fails. It seems some C calls are needed  
     84                # for things to resolve; race condition somewhere?  
     85                # securechannel throws a socket.error (107) if not. 
     86                # Note that the old code (using _v_http_server) would 
     87                # fail too if it weren't for more C calls (through 
     88                # dict lookups) and persistence mechanisms. 
     89                repr(gHttpServer) 
     90                gHttpServer.debugger.ConnectToClient() 
     91            except: 
     92                # bare except, but with re-raise 
     93                raise 
     94    finally: 
     95        status['completed'] = 1 
    7396 
    7497 
     
    292315        # Schedule the connection 
    293316        if self.hasStarted(): 
    294             status_dict = {'completed': 0} 
    295             func = lambda do_connect=self.__do_connect, dict=status_dict: \ 
    296                    do_connect(dict) 
    297             gHttpServer.RunOnDebugThread(func) 
     317            status = {'completed': 0} 
     318            cb = lambda conn=connectToIDECallback, s=status: conn(s) 
     319            gHttpServer.RunOnDebugThread(cb) 
    298320             
    299321            # Wait up to 3 seconds for connection 
    300322            start_time = time.time() 
    301             while time.time() < start_time + 5 and not status_dict['completed']: 
     323            while time.time() < start_time + 5 and not status['completed']: 
    302324                time.sleep(0.05) 
    303             if not status_dict['completed']: 
     325            if not status['completed']: 
    304326                raise IDEConnectionTimeOut 
    305          
    306     security.declarePrivate('__do_connect') 
    307     def __do_connect(self, status_dict): 
    308         "Function to try connecting to client; gets run on the debug thread." 
    309         try: 
    310             if self.hasStarted(): 
    311                 if gHttpServer.debugger is not None: 
    312                     # temporary try: except: wrapper to work around exception 
    313                     # detection in the debugger 
    314                     try: 
    315                         # Without the following line, the debugger-to-IDE  
    316                         # auto-connect fails. It seems some C calls are needed  
    317                         # for things to resolve; race condition somewhere?  
    318                         # securechannel throws a socket.error (107) if not. 
    319                         # Note that the old code (using _v_http_server) would 
    320                         # fail too if it weren't for more C calls (through 
    321                         # dict lookups) and persistence mechanisms. 
    322                         repr(gHttpServer) 
    323                         gHttpServer.debugger.ConnectToClient() 
    324                     except: 
    325                         # bare except, but with re-raise 
    326                         raise 
    327         finally: 
    328             status_dict['completed'] = 1 
    329327 
    330328    security.declarePrivate('_import_netserver')