@@ -31,9 +31,13 @@ class IOSDebugService implements IDebugService {
31
31
private $utils : IUtils ,
32
32
private $iOSNotification : IiOSNotification ,
33
33
private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
34
- private $socketProxyFactory : ISocketProxyFactory ) { }
34
+ private $processService : IProcessService ,
35
+ private $socketProxyFactory : ISocketProxyFactory ) {
36
+ this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
37
+ }
35
38
36
39
private _lldbProcess : ChildProcess ;
40
+ private _sockets : net . Socket [ ] = [ ] ;
37
41
38
42
public get platform ( ) : string {
39
43
return "ios" ;
@@ -76,6 +80,11 @@ class IOSDebugService implements IDebugService {
76
80
77
81
public debugStop ( ) : IFuture < void > {
78
82
return ( ( ) => {
83
+ this . $socketProxyFactory . stopServer ( ) ;
84
+ for ( let socket of this . _sockets ) {
85
+ socket . destroy ( ) ;
86
+ }
87
+ this . _sockets = [ ] ;
79
88
if ( this . _lldbProcess ) {
80
89
this . _lldbProcess . stdin . write ( "process detach\n" ) ;
81
90
this . _lldbProcess . kill ( ) ;
@@ -105,19 +114,19 @@ class IOSDebugService implements IDebugService {
105
114
if ( lineText && _ . startsWith ( lineText , this . $projectData . projectId ) ) {
106
115
let pid = _ . trimStart ( lineText , this . $projectData . projectId + ": " ) ;
107
116
this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
108
- this . _lldbProcess . stdin . write ( "process continue\n" ) ;
117
+ this . _lldbProcess . stdin . write ( "process continue\n" ) ;
109
118
} else {
110
119
process . stdout . write ( line + "\n" ) ;
111
120
}
112
121
} ) ;
113
122
114
- this . wireDebuggerClient ( ( ) => net . connect ( inspectorBackendPort ) ) . wait ( ) ;
123
+ this . wireDebuggerClient ( ) . wait ( ) ;
115
124
} ) . future < void > ( ) ( ) ;
116
125
}
117
126
118
127
private emulatorStart ( ) : IFuture < void > {
119
128
return ( ( ) => {
120
- this . wireDebuggerClient ( ( ) => net . connect ( inspectorBackendPort ) ) . wait ( ) ;
129
+ this . wireDebuggerClient ( ) . wait ( ) ;
121
130
122
131
let attachRequestMessage = this . $iOSNotification . attachRequest ;
123
132
@@ -152,7 +161,7 @@ class IOSDebugService implements IDebugService {
152
161
let readyForAttachTimeout = this . getReadyForAttachTimeout ( timeout ) ;
153
162
154
163
this . $iOSSocketRequestExecutor . executeLaunchRequest ( device , timeout , readyForAttachTimeout , shouldBreak ) . wait ( ) ;
155
- this . wireDebuggerClient ( ( ) => device . connectToPort ( inspectorBackendPort ) ) . wait ( ) ;
164
+ this . wireDebuggerClient ( device ) . wait ( ) ;
156
165
} ) . future < void > ( ) ( ) ;
157
166
}
158
167
@@ -167,13 +176,17 @@ class IOSDebugService implements IDebugService {
167
176
return ( ( ) => {
168
177
let timeout = this . getReadyForAttachTimeout ( ) ;
169
178
this . $iOSSocketRequestExecutor . executeAttachRequest ( device , timeout ) . wait ( ) ;
170
- this . wireDebuggerClient ( ( ) => device . connectToPort ( inspectorBackendPort ) ) . wait ( ) ;
179
+ this . wireDebuggerClient ( device ) . wait ( ) ;
171
180
} ) . future < void > ( ) ( ) ;
172
181
}
173
182
174
- private wireDebuggerClient ( factory : ( ) => net . Socket ) : IFuture < void > {
183
+ private wireDebuggerClient ( device ?: Mobile . IiOSDevice ) : IFuture < void > {
175
184
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 ( ) ;
177
190
this . executeOpenDebuggerClient ( socketProxy ) . wait ( ) ;
178
191
} ) . future < void > ( ) ( ) ;
179
192
}
0 commit comments