@@ -12,48 +12,54 @@ import { uriTransformerPath } from "vs/server/src/util";
1212import { IExtHostReadyMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol" ;
1313
1414export abstract class Connection {
15- protected readonly _onClose = new Emitter < void > ( ) ;
15+ private readonly _onClose = new Emitter < void > ( ) ;
1616 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+
1942 /**
2043 * Set up the connection on a new socket.
2144 */
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 ;
2447}
2548
2649/**
2750 * Used for all the IPC channels.
2851 */
2952export 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 ( ) ;
3957 }
4058
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 {
4360 this . protocol . beginAcceptReconnection ( socket , buffer ) ;
4461 this . protocol . endAcceptReconnection ( ) ;
4562 }
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- }
5763}
5864
5965export class ExtensionHostConnection extends Connection {
@@ -70,18 +76,14 @@ export class ExtensionHostConnection extends Connection {
7076 this . protocol . getUnderlyingSocket ( ) . pause ( ) ;
7177 }
7278
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 ( ) ;
8182 }
83+ this . protocol . getSocket ( ) . end ( ) ;
8284 }
8385
84- public reconnect ( socket : ISocket , buffer : VSBuffer ) : void {
86+ protected doReconnect ( socket : ISocket , buffer : VSBuffer ) : void {
8587 // This is just to set the new socket.
8688 this . protocol . beginAcceptReconnection ( socket , null ) ;
8789 this . protocol . dispose ( ) ;
0 commit comments