@@ -12,48 +12,54 @@ import { uriTransformerPath } from "vs/server/src/util";
12
12
import { IExtHostReadyMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol" ;
13
13
14
14
export abstract class Connection {
15
- protected readonly _onClose = new Emitter < void > ( ) ;
15
+ private readonly _onClose = new Emitter < void > ( ) ;
16
16
public readonly onClose = this . _onClose . event ;
17
- protected disposed : boolean = false ;
18
- public constructor ( protected protocol : Protocol ) { }
17
+ private disposed = false ;
18
+ private _offline : number | undefined ;
19
+
20
+ public constructor ( protected protocol : Protocol ) {
21
+ protocol . onClose ( ( ) => this . dispose ( ) ) ; // Explicit close.
22
+ protocol . onSocketClose ( ( ) => this . _offline = Date . now ( ) ) ; // Might reconnect.
23
+ }
24
+
25
+ public get offline ( ) : number | undefined {
26
+ return this . _offline ;
27
+ }
28
+
29
+ public reconnect ( socket : ISocket , buffer : VSBuffer ) : void {
30
+ this . _offline = undefined ;
31
+ this . doReconnect ( socket , buffer ) ;
32
+ }
33
+
34
+ public dispose ( ) : void {
35
+ if ( ! this . disposed ) {
36
+ this . disposed = true ;
37
+ this . doDispose ( ) ;
38
+ this . _onClose . fire ( ) ;
39
+ }
40
+ }
41
+
19
42
/**
20
43
* Set up the connection on a new socket.
21
44
*/
22
- public abstract reconnect ( socket : ISocket , buffer : VSBuffer ) : void ;
23
- protected abstract dispose ( ) : void ;
45
+ protected abstract doReconnect ( socket : ISocket , buffer : VSBuffer ) : void ;
46
+ protected abstract doDispose ( ) : void ;
24
47
}
25
48
26
49
/**
27
50
* Used for all the IPC channels.
28
51
*/
29
52
export class ManagementConnection extends Connection {
30
- private timeout : NodeJS . Timeout | undefined ;
31
- private readonly wait = 1000 * 60 ;
32
-
33
- public constructor ( protocol : Protocol ) {
34
- super ( protocol ) ;
35
- protocol . onClose ( ( ) => this . dispose ( ) ) ;
36
- protocol . onSocketClose ( ( ) => {
37
- this . timeout = setTimeout ( ( ) => this . dispose ( ) , this . wait ) ;
38
- } ) ;
53
+ protected doDispose ( ) : void {
54
+ this . protocol . sendDisconnect ( ) ;
55
+ this . protocol . dispose ( ) ;
56
+ this . protocol . getSocket ( ) . end ( ) ;
39
57
}
40
58
41
- public reconnect ( socket : ISocket , buffer : VSBuffer ) : void {
42
- clearTimeout ( this . timeout as any ) ; // Not sure why the type doesn't work.
59
+ protected doReconnect ( socket : ISocket , buffer : VSBuffer ) : void {
43
60
this . protocol . beginAcceptReconnection ( socket , buffer ) ;
44
61
this . protocol . endAcceptReconnection ( ) ;
45
62
}
46
-
47
- protected dispose ( ) : void {
48
- if ( ! this . disposed ) {
49
- clearTimeout ( this . timeout as any ) ; // Not sure why the type doesn't work.
50
- this . disposed = true ;
51
- this . protocol . sendDisconnect ( ) ;
52
- this . protocol . dispose ( ) ;
53
- this . protocol . getSocket ( ) . end ( ) ;
54
- this . _onClose . fire ( ) ;
55
- }
56
- }
57
63
}
58
64
59
65
export class ExtensionHostConnection extends Connection {
@@ -70,18 +76,14 @@ export class ExtensionHostConnection extends Connection {
70
76
this . protocol . getUnderlyingSocket ( ) . pause ( ) ;
71
77
}
72
78
73
- protected dispose ( ) : void {
74
- if ( ! this . disposed ) {
75
- this . disposed = true ;
76
- if ( this . process ) {
77
- this . process . kill ( ) ;
78
- }
79
- this . protocol . getSocket ( ) . end ( ) ;
80
- this . _onClose . fire ( ) ;
79
+ protected doDispose ( ) : void {
80
+ if ( this . process ) {
81
+ this . process . kill ( ) ;
81
82
}
83
+ this . protocol . getSocket ( ) . end ( ) ;
82
84
}
83
85
84
- public reconnect ( socket : ISocket , buffer : VSBuffer ) : void {
86
+ protected doReconnect ( socket : ISocket , buffer : VSBuffer ) : void {
85
87
// This is just to set the new socket.
86
88
this . protocol . beginAcceptReconnection ( socket , null ) ;
87
89
this . protocol . dispose ( ) ;
0 commit comments