@@ -31,9 +31,13 @@ class IOSDebugService implements IDebugService {
3131 private $utils : IUtils ,
3232 private $iOSNotification : IiOSNotification ,
3333 private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
34- private $socketProxyFactory : ISocketProxyFactory ) { }
34+ private $processService : IProcessService ,
35+ private $socketProxyFactory : ISocketProxyFactory ) {
36+ this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
37+ }
3538
3639 private _lldbProcess : ChildProcess ;
40+ private _sockets : net . Socket [ ] = [ ] ;
3741
3842 public get platform ( ) : string {
3943 return "ios" ;
@@ -76,6 +80,11 @@ class IOSDebugService implements IDebugService {
7680
7781 public debugStop ( ) : IFuture < void > {
7882 return ( ( ) => {
83+ this . $socketProxyFactory . stopServer ( ) ;
84+ for ( let socket of this . _sockets ) {
85+ socket . destroy ( ) ;
86+ }
87+ this . _sockets = [ ] ;
7988 if ( this . _lldbProcess ) {
8089 this . _lldbProcess . stdin . write ( "process detach\n" ) ;
8190 this . _lldbProcess . kill ( ) ;
@@ -105,19 +114,19 @@ class IOSDebugService implements IDebugService {
105114 if ( lineText && _ . startsWith ( lineText , this . $projectData . projectId ) ) {
106115 let pid = _ . trimStart ( lineText , this . $projectData . projectId + ": " ) ;
107116 this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
108- this . _lldbProcess . stdin . write ( "process continue\n" ) ;
117+ this . _lldbProcess . stdin . write ( "process continue\n" ) ;
109118 } else {
110119 process . stdout . write ( line + "\n" ) ;
111120 }
112121 } ) ;
113122
114- this . wireDebuggerClient ( ( ) => net . connect ( inspectorBackendPort ) ) . wait ( ) ;
123+ this . wireDebuggerClient ( ) . wait ( ) ;
115124 } ) . future < void > ( ) ( ) ;
116125 }
117126
118127 private emulatorStart ( ) : IFuture < void > {
119128 return ( ( ) => {
120- this . wireDebuggerClient ( ( ) => net . connect ( inspectorBackendPort ) ) . wait ( ) ;
129+ this . wireDebuggerClient ( ) . wait ( ) ;
121130
122131 let attachRequestMessage = this . $iOSNotification . attachRequest ;
123132
@@ -152,7 +161,7 @@ class IOSDebugService implements IDebugService {
152161 let readyForAttachTimeout = this . getReadyForAttachTimeout ( timeout ) ;
153162
154163 this . $iOSSocketRequestExecutor . executeLaunchRequest ( device , timeout , readyForAttachTimeout , shouldBreak ) . wait ( ) ;
155- this . wireDebuggerClient ( ( ) => device . connectToPort ( inspectorBackendPort ) ) . wait ( ) ;
164+ this . wireDebuggerClient ( device ) . wait ( ) ;
156165 } ) . future < void > ( ) ( ) ;
157166 }
158167
@@ -167,13 +176,17 @@ class IOSDebugService implements IDebugService {
167176 return ( ( ) => {
168177 let timeout = this . getReadyForAttachTimeout ( ) ;
169178 this . $iOSSocketRequestExecutor . executeAttachRequest ( device , timeout ) . wait ( ) ;
170- this . wireDebuggerClient ( ( ) => device . connectToPort ( inspectorBackendPort ) ) . wait ( ) ;
179+ this . wireDebuggerClient ( device ) . wait ( ) ;
171180 } ) . future < void > ( ) ( ) ;
172181 }
173182
174- private wireDebuggerClient ( factory : ( ) => net . Socket ) : IFuture < void > {
183+ private wireDebuggerClient ( device ?: Mobile . IiOSDevice ) : IFuture < void > {
175184 return ( ( ) => {
176- let socketProxy = this . $socketProxyFactory . createSocketProxy ( factory ) . wait ( ) ;
185+ let socketProxy = this . $socketProxyFactory . createSocketProxy ( ( ) => {
186+ let socket = device ? device . connectToPort ( inspectorBackendPort ) : net . connect ( inspectorBackendPort ) ;
187+ this . _sockets . push ( socket ) ;
188+ return socket ;
189+ } ) . wait ( ) ;
177190 this . executeOpenDebuggerClient ( socketProxy ) . wait ( ) ;
178191 } ) . future < void > ( ) ( ) ;
179192 }
0 commit comments