Skip to content

Commit

Permalink
Handle socket close event
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Mar 9, 2016
1 parent 8c0649e commit 16efb4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/dbgp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export abstract class DbgpConnection extends EventEmitter {
this._chunks = [];
socket.on('data', (data: Buffer) => this._handleDataChunk(data));
socket.on('error', (error: Error) => this.emit('error'));
socket.on('close', () => this.emit('close'));
}

private _handleDataChunk(data: Buffer) {
Expand Down
23 changes: 16 additions & 7 deletions src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,22 @@ class PhpDebugSession extends vscode.DebugSession {
}
this._connections.set(connection.id, connection);
this._waitingConnections.add(connection);
connection.on('error', (error: Error) => {
this.sendEvent(new vscode.OutputEvent(error.message));
this.sendEvent(new vscode.ThreadEvent('exited', connection.id));
connection.close();
this._connections.delete(connection.id);
this._waitingConnections.delete(connection);
});
const disposeConnection = (error?: Error) => {
if (this._connections.has(connection.id)) {
if (args.log) {
this.sendEvent(new vscode.OutputEvent('connection ' + connection.id + ' closed\n'));
}
if (error) {
this.sendEvent(new vscode.OutputEvent(error.message));
}
this.sendEvent(new vscode.ThreadEvent('exited', connection.id));
connection.close();
this._connections.delete(connection.id);
this._waitingConnections.delete(connection);
}
};
connection.once('error', disposeConnection);
connection.once('close', disposeConnection);
connection.waitForInitPacket()
.then(() => {
this.sendEvent(new vscode.ThreadEvent('started', connection.id));
Expand Down

0 comments on commit 16efb4a

Please sign in to comment.